PDA

View Full Version : Offset turret rotation



SticksStones
February 8th, 2009, 08:47 PM
Hi

I know this will be an easy question for anyone with better math than me, but I'm really stuck!
I'm making a top down game - with spaceships! - I'm always pushing the boundaries :ducky:
The spaceship has a gun that turns, if a bullet was fired from the end of the gun, where would the bullet spawn?

Thanks

justkevin
February 8th, 2009, 10:21 PM
Translate the angle of the turret to radians. Math.cos(angle) will give its x offset component, Math.sin(angle) will its y offset component.

scottc
February 8th, 2009, 11:37 PM
Dont' forget that the angle will be in radians.

and to get it to align up with the length of the barrel you need to do the following:


Math.sin(angle) * distanceFromCenter;
Math.cos(angle) * distanceFromCenter;

SticksStones
February 9th, 2009, 11:29 AM
Dont' forget that the angle will be in radians.

and to get it to align up with the length of the barrel you need to do the following:
ActionScript Code:

Math.sin(angle) * distanceFromCenter;
Math.cos(angle) * distanceFromCenter;




How can i do this with the point offset twice?
It needs to take into account the rotation of the spaceship, then the rotation of the turret.

Thanks