0
\$\begingroup\$

In my game I have a rocket which is traveling horizontally across the screen.

What I am trying to do is when the player runs out of fuel, the rockets engine stops (already coded) and then the rocket will slowly rotate to point at an almost 45 degree angle and fall down off the screen as gravity takes its affect.

How do I do this?

\$\endgroup\$
2
  • \$\begingroup\$ Are you using rigidbodies? \$\endgroup\$
    – Joe
    Apr 15, 2016 at 11:29
  • \$\begingroup\$ Sounds like you're in a 2D project. The object's transform.eulerAngles.y would be the one to modify. \$\endgroup\$ May 16, 2016 at 4:10

2 Answers 2

1
\$\begingroup\$

You need to rotate the rocket after each "physics" update (I think you are not actually using rigidbodies or physics), like so:

enter image description here

You just need the rocket's transform.forward to always point in the same direction as its' velocity, regardless of how you calculate velocity. If "forward" is always pointing in the actual correct direction, you can just push the rocket along its' local Z axis rather than pushing it through world-space.

\$\endgroup\$
0
\$\begingroup\$

try this:

  • put an empty game object a few units below the rocket, but horizontally in the middle of it. (the more units below the rocket, the slower the rotation will be ).

  • use this code ( just a concept )


//note that this code won't work like this, it's just a guideline

public float speed = 0.2f;
void Update ()
{
    if (outOfFuel)
        rocket.transform.Rotate ( emptyGameObject.transform.forward * speed * Time.deltaTime );
    /* You will see that the rocket won't stop spinning, it's ok.
     * Just press play, and when you feel the rocket is facing the direction
     * you want to set as a limit, go to the code and change it like this:
     * if (outOfFuel && rocket.transform.eulerAngles.z <= limitRotation )
     * where 'limitRoation' is a float.
     * Also, if after you change the code the rocket stops spinning or similar,
     * change the '<=' symbol with a '>=' symbol.
     */
}

Hope it helps, if anything, let us know.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .