The agony of angles
![forklift](http://forums.gamesalad.com/applications/dashboard/design/images/defaulticon.png)
Any time mathematics is involved, I start to hyperventilate. I've tried a number of ways of solving this problem, but they all fail hard.
The simplest idea I can apply my problem to is a rocket flying upward. When the rocket turns, the thrust is coming from an angle which is directly under the rocket. This was achieved simply by using the rotation command. However, if i want particles to come out of the rocket along that same angle of thrust... (to simulate fire from the engine) what in the world do i need to do to get it to rotate to that same angle?
The simplest idea I can apply my problem to is a rocket flying upward. When the rocket turns, the thrust is coming from an angle which is directly under the rocket. This was achieved simply by using the rotation command. However, if i want particles to come out of the rocket along that same angle of thrust... (to simulate fire from the engine) what in the world do i need to do to get it to rotate to that same angle?
Comments
Is there a way to say...
assign the rocket's rotation to game.rocketrotationX, game.rocketrotationY and having another actor locked to a position at the game.rocketrotationX + 10, game.rocketrotationY + 10? Yes, I know that wouldn't actually 'predict' where the rocket will be. Substitute mysterious equation for +10.
Then in the game rotate the actor instance 90 degrees to point up.
Particles offset X = cos(self.rotation+180)*self.height/2
Particles offset y = sin(self.rotation+180)*self.height/2
Particles angle 180 relative to actor
I will try this when I get off of work. In the meantime, can you help me break down this equation?
I really want to understand what's happening so I'm not just copying and pasting:
Particles offset X = cos(self.rotation+180)*self.height/2
Particles offset y = sin(self.rotation+180)*self.height/2
On self.rotation, we are adding 180 so that the particles rotate 180 (or opposite of the actor's facing value)
Why are we multiplying self.height and then dividing by 2?
After tinkering with the formula you provided above, I messed around for 2 hours and really took an understanding of what each element does. For those interested, ended up with:
Particles offset X = cos(self.rotation+180)*self.width/4
Particles offset y = sin(self.rotation+180)*self.height/2-100
The rocket actor was skinny and long, so the x offset had to use *self.width rather than height. I also had to divide by 4 for the purpose of my actor, because the rotation speed was such that if I rotated say, more than 45% from straight up (90 degrees relative to the actor) it would stray. /4 makes it stray less at extreme angles, but it still does stray (no horizontal flight). So in this case, i'd just constrain the actor's rotation to no more than 45 degrees of turn in either x direction (relative to 90). So, my full range of tilt would be min45, max135.
Since the Y of my actor was so tall, I just offset Y (-100) so that it looked like they were coming out of the engine at the bottom of the actor.
You are the man!
Thanks so much for this simple solution.