Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Weird curveangle behavior

Author
Message
Cescano
9
Years of Service
User Offline
Joined: 4th Sep 2014
Location: Italy
Posted: 1st Apr 2016 17:41
I am using curvevalue to interpolate smoothly positions data on my multiplayer game, now I am trying to smooth also the rotation using curveangle but it has weird behavior, look at the code below:

revenant chaos
Valued Member
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 1st Apr 2016 18:34 Edited at: 1st Apr 2016 18:38
The problem is that the curveangle command was intended for use with floats, and so what you see here is a side effect of dropping the decimal digits when casting from float to integer. Similarly to the curvevalue command, it seems the equation used by curveangle is somewhere along the lines of:

resultangle = currentangle + ( ( destinationangle - currentangle ) / speedvalue )

When rotating from 300 to 100, curveangle attempts to take the shortest path by increasing the angle with the intent of wrapping back around to complete the transition (300->359->0->100). Because your speed value is set to 100, when the current angle = 0 the result returned by curveangle is 1 because:

resultangle = 0+( (100-0) /100) = 0+(100/100) = 0+1 = 1

However during the next iteration (where currentangle=1), the calculation becomes:

resultangle = 1+( (100-1) /100) = 1+(99/100) = 1+0.99 = 1.99

Now when attempting to store the floating-point value of 1.99 within an Integer, everything after the decimal point is dropped and becomes a value of 1.
Cescano
9
Years of Service
User Offline
Joined: 4th Sep 2014
Location: Italy
Posted: 1st Apr 2016 19:30 Edited at: 1st Apr 2016 19:42
even trying with decimals (300.111 and 100.111) I have the same problem

Edit:

I forgot that the array must be set to float with the damn #, I am getting too used with php where every variable is just $Variable.


Thank you though for the help, I am gonna test this now on the game and hope it will works fine (on the small test it worked).
Cescano
9
Years of Service
User Offline
Joined: 4th Sep 2014
Location: Italy
Posted: 1st Apr 2016 20:00
It works like a charm now, thank you!
revenant chaos
Valued Member
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 1st Apr 2016 20:21
You're welcome, always happy to help.

Login to post a reply

Server time is: 2024-04-26 16:40:57
Your offset time is: 2024-04-26 16:40:57