Direction from angle

BlitzMax Forums/BlitzMax Programming/Direction from angle

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Here you go:
Local angle, speed
Local xrate, yrate
Local x, y

angle = 150
speed = 5

xrate = speed * Sin( angle )
yrate = speed * Cos( angle )

x = x + xrate
y = y + yrate

Angle is of course the angle of the direction of your ant. Speed is how fast your ant is going. Xrate and Yrate are the rate that x and y are changed by. They are calculated as above and added to their respective variables.

This is how a circle is calculated. If you did a For angle = 0 to 360 sort of thing, it would calculate a circle that has a radius of 5, because a circle is calculated X = Radius * Sin( Degree ), and Y = Radius * Cos( Degree ). So in reality you are calculating a circle for one specific degree.

Hope it helps.

<EDIT> I think there is a sample of Asteroids that comes with BMX if not you could try B+. Look at those examples and you can see how they do it.