Jump script deleting shape
4 posts • Page 1 of 1
Jump script deleting shape
I am using the following script to make my figure jump when certain conditions are met:
Code in words: calculate how much of the horizontal and vertical vel. is beeing kept depending on the current gravity angle's sin/cos value, then add the value 4 combined with the oposite value(cos/sin)
What happens is that when the gravity angle offset is normal(=0) the script works, but with a angle of -1/2 * math.pi (or 90 degrees) the cube instantly deletes itself, simply*poof* and it's gone right in place
Could someone analyze the happenings behind this script and try to tell me what causes the cube to vanish?
EDIT: The ^ 2 ^ 0.5 is to positivate the value, so the cube doesnt suddently makes a backwards move
- Code: Select all
e.this.vel = [e.this.vel(0) * ((math.cos(sim.gravityangleoffset) ^ 2 ^ 0.5)) + 4 * math.sin(sim.gravityangleoffset), e.this.vel(1) * ((math.sin(sim.gravityangleoffset) ^ 2 ^ 0.5)) + 4 * math.cos(sim.gravityangleoffset)];
Code in words: calculate how much of the horizontal and vertical vel. is beeing kept depending on the current gravity angle's sin/cos value, then add the value 4 combined with the oposite value(cos/sin)
What happens is that when the gravity angle offset is normal(=0) the script works, but with a angle of -1/2 * math.pi (or 90 degrees) the cube instantly deletes itself, simply*poof* and it's gone right in place
Could someone analyze the happenings behind this script and try to tell me what causes the cube to vanish?
EDIT: The ^ 2 ^ 0.5 is to positivate the value, so the cube doesnt suddently makes a backwards move
- FRA32
- Posts: 229
- Joined: Wed Dec 03, 2014 9:51 pm
Re: Jump script deleting shape
What I found happens is the value in vel(0) and/or vel(1) becomes NAN (Not A Number) which is usually due to an invalid math operation. When vel(0) or vel(1) become NAN, the geometry will self-destruct. I haven't figured out why your math is causing the NAN when gravity angle becomes < -90, but this will give you some idea what to look for.
-

Xray - Posts: 501
- Joined: Sun Jun 17, 2012 6:12 am
- Location: USA
Re: Jump script deleting shape
The ^ 2 ^ 0.5 is to positivate the value, so the cube doesnt suddently makes a backwards move
That's the reason:
> -1 ^ 2 ^ 0.5
-1
> (- 1 ^ 2) ^ 0.5
NaN
> (- 1) ^ 2 ^ 0.5
NaN
> ((- 1) ^ 2) ^ 0.5
1
Dream of Algodoo as game development engine...
-

Kilinich - [Best bug reporter 2010]
- Posts: 2098
- Joined: Mon Aug 31, 2009 8:27 pm
- Location: South Russia
Re: Jump script deleting shape
Thanks guys, you saved one gamer's game series
- FRA32
- Posts: 229
- Joined: Wed Dec 03, 2014 9:51 pm
4 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 2 guests



