Curve Angle

Monkey Forums/Monkey Programming/Curve Angle

monotonic(Posted 2013) [#1]
Hi All,

I'm new to Monkey but have been using various different engines for a few years now.

I'm currently working a car game and have hit a bit of a wall. I need to smoothly rotate from one angle to another, in other engines I would use something like Lerp (3D) or CurveAngle. I cannot seem to find a similar function in Monkey.

Say my (top down 2D) car is facing 45 degress and my next waypoint is at 90 degress, how would I smoothly rotate the angle?

Thanks in advance.


Amon(Posted 2013) [#2]
Sin/Cos/Atan/Atan2

Search for those commands.


AdamRedwoods(Posted 2013) [#3]
it's called "tweening" for 2d.

check out monkey/bananas/skn3/tweening
or
diddy
http://monkeycoder.co.nz/Community/posts.php?topic=4589
or
http://monkeycoder.co.nz/Community/posts.php?topic=4173
or box2d
https://code.google.com/p/monkeybox2d/


silentshark(Posted 2013) [#4]
Hi Monotonic,

Might have misunderstood.. can't you just have a variable for the angle, increment it in the OnUpdate loop, then use the rotation parameter to DrawImage in your OnRender loop?


monotonic(Posted 2013) [#5]
Sin/Cos/Atan/Atan2

Search for those commands.


Calculating the angle is not a problem, I got my head around basic trigonometry many moons ago.

it's called "tweening" for 2d.

check out monkey/bananas/skn3/tweening


Tweening! That is what I was looking for, I'm used to working in 3D so was searching for things like 2D Lerp and 2D Interpolation which returned nothing useful. Thank you.


ziggy(Posted 2013) [#6]
That's it:
Function Lerp:Float(value1:float, value2:float, speed:float)
	Local dif:Float = value2 - value1
	speed = Abs(speed)
	If Abs(dif) < speed Then Return value2
	Return value1 + speed * Sgn(value2 - value1)
End


You can also use non lienar interpolation for "slowly stopping" interpolation:

Function Eerp:Float(value1:float, value2:float, speed:float)
	Local dif:Float = value2 - value1
	Const NARROW_FACTOR:Float = 10.0 'Avoid interpolation to be too quick.
	value1 += dif * (speed / NARROW_FACTOR)
	Return value1
End


If you multiply the speeed factor by any deltatime factor, you should get smooth tweening if this interpolation is used on animations.

Maybe this could be built-in to the Monkey Math module?


monotonic(Posted 2013) [#7]
@ziggy

Interesting, I will try that function out when I get home after work. Thank you for that :) It really should be built into the Monkey framework as this method is used quite frequently in many different languages, I was surprised when I couldn't find it in the docs.

Edit: I'm using you IDE btw, great work!

Edit 2: Does this forum not send out notification emails when a reply is posted?


ziggy(Posted 2013) [#8]
I'm using you IDE btw, great work!
Thanks! That's very appreciated!
Does this forum not send out notification emails when a reply is posted?
You have to subscribe to the thread. Notice the small "subscribe" label at the bottom left area of the page.
Edit: To use it on a 2D vector, be sure to normalize the vector and multiply speed for X and Y of the normalized vector. The same applies for 3D, etc.


silentshark(Posted 2013) [#9]
Well, I'm a complete muppet when it comes to this stuff. Anyone got a nice pointer to what tweening is, and how it can help?


monotonic(Posted 2013) [#10]
In the context of what I'm doing its the process of gradually rotating from one angle to another. For instance cars don't go from one direction to another instantly, they gradually turn until they reach the desired angle. The term also applies to moving from one animation to another in a smooth manner rather than jumping instantly.


silentshark(Posted 2013) [#11]
Ah, sounds exactly like the kind of stuff I've been wanting to do..