Jump script deleting shape

About advanced scenes, and the Thyme scripting language used in Algodoo.

Jump script deleting shape

Postby FRA32 » Sun Feb 08, 2015 1:20 am

I am using the following script to make my figure jump when certain conditions are met:
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

Postby Xray » Mon Mar 16, 2015 2:25 am

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.
User avatar
Xray
 
Posts: 500
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: Jump script deleting shape

Postby Kilinich » Mon Mar 16, 2015 10:26 am

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...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: Jump script deleting shape

Postby FRA32 » Thu Apr 02, 2015 11:31 am

Thanks guys, you saved one gamer's game series
FRA32
 
Posts: 229
Joined: Wed Dec 03, 2014 9:51 pm


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 3 guests

cron