My object has a point x,y this always changes as the mouse drags it around inside a 800×600 box. My object also rotates to an angle set by the mouse it can be any 360 degree. My issue is now how to shoot a projectile from that angle and of course from that XY position. The projectile only needs to go in a straight line but It need to be moving in the correct angle as the Main object was. I have the angle and I have the XY position all I need is the formula to make it move across the grid from the appropriate angle.
EDIT –
Current JSFIDDLE with projectile not shooting at the correct angle.
http://jsfiddle.net/vbk4Z/16/
The standard formulae are:
Where
(x0, y0)are the original position,vis the velocity required,thetais the angle (in radians) andtis the time since the projectile was fired.Note that this uses the classic cartisian convention of angles being measured anticlockwise relative to the positive x axis, and with the y axis facing up.
If you’re using browser coordinates, and happen to have chosen to use bearings (clockwise relative to “up” / “north”) then you need to swap some signs and trig functions: