-1

I've looked through the suggested, but I can't see exactly what I need. I want to calculate the vector needed for forward motion of a rotated sprite. At the moment I have:

        sprite.Rotation = 0
        sprite.Velocity = New Vector2(0, -1)

This is perfect, my sprite moves up my arena. But what I need is:

        sprite.Rotation = RN.Next(0, 360)
        sprite.Velocity = New Vector2(??,??)

I know it's going to be a PI thing but that's where my brain runs out! Could someone with a better brain please post the equation I need?

Many thank yous.

1 Answers1

1

All you need is basic trigonometry. Unfortunately I don't have time to explain, but here is the formulas.

x = speed *  sin(rotation)
y = speed * -cos(rotation)

This is if positive y is down and positive x is to the left, or

x = speed * -sin(rotation)
y = speed * -cos(rotation)

If positive y is down and positive x is to the right.

Please note whether your trigonometric functions take rotation to be in radians or degrees and convert acordingly.

Christer
  • 1,015
  • 6
  • 13