The agony of angles

forkliftforklift Member Posts: 386
edited November -1 in Working with GS (Mac)
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?

Comments

  • forkliftforklift Member Posts: 386
    Man, if that's really what I overlooked I'm gonna punch myself in the junk! lol
  • forkliftforklift Member Posts: 386
    tshirt... what are your thoughts about figuring out the angle of direction that the rocket would be traveling?

    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.
  • ORBZORBZ Member Posts: 1,304
    First of all to make everything simple orient your spaceship art such that the top of the ship is pointing right along the x axis. This is 0 degrees.

    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
  • ORBZORBZ Member Posts: 1,304
    Also see my trig 101 demo on my profile.
  • forkliftforklift Member Posts: 386
    Thanks everyone! ORBZ, this really does simplify things (setting original rotation to 0) I never thought of that.

    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?
  • forkliftforklift Member Posts: 386
    I looked at the Trig 101 example, and began to understand how the sin and cos function work in GS. Thanks for all the help, ORBZ!

    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.
  • HaansplosionHaansplosion Member Posts: 2
    Dear ORBZ,

    You are the man!

    Thanks so much for this simple solution.
Sign In or Register to comment.