Apply Linear Impulse?

Topics: Developer Forum
Aug 10, 2011 at 12:32 PM

Hi Guys quick question...

I have a player middle of the screen, i calculate the radian to where the mouse is. I want to apply a Linear Impluse to that direction ie. shooting simply...

projectiles[bulletCount2].ApplyLinearImpulse(Vector2);

projectiles[bulletCount2].ApplyLinearImpulse(Vector2, Vector2);

How do you apply the radian angle to a simple Linear Impulse?

I am creating a radian by getting the x, y from the mouse and then putting it through Math.Tan, which give me a value from 0 to 3 && 0 to -3 depending on where the mouse is located.

Any suggestions?

Thanks

Aug 10, 2011 at 12:42 PM
Edited Aug 10, 2011 at 12:44 PM

Sorry to waise time... just figured it out...

float radians = (float)Math.Atan2(mouseDistanceFromCenter.X, mouseDistanceFromCenter.Y);

Vector2 newVector2 = new Vector2((float)Math.Cos(radians), (float)Math.Sin(radians));

Hope this can help anyone else.

Mal

 

EDIT: got the Cos & Sin wrong way around...

Vector2 projectileDirection = (new Vector2((float)Math.Sin(radians), (float)Math.Cos(radians)));