I need to know how to move my sprite along a path at a certain angle. Can anybody help me with this?
Printable View
I need to know how to move my sprite along a path at a certain angle. Can anybody help me with this?
This is pretty easy. Take the angle, and convert it into a unit vector:
Remember that angle must be in radians. If it is in degrees, you have to convert. just use the following:Code:Type Vector
x as Single
y as Single
End Type
...
Dim dir as Vector
dir.x = cos(angle)
dir.y = sin(angle)
... and use radians in place of the angle variable above.Code:radians = angle * (3.14159 / 180)
Now, when you want to move, you need to know the speed you want to move your sprite at. Then, use this:
Z.Code:sprite.x = sprite.x + sprite.speed * dir.x
sprite.y = sprite.y + sprite.speed * dir.y
Thanks man. That's exactly what I wanted. I'm going to try that out right now.
Yeah. It's common practice to do them as constants.
Const PI = 3.14159
Const RAD = PI / 180
Const DEG = 180 / PI
Pi, radians, degrees. There you are!