Moving in correct direction, after rotating

Hi

I need some help here, I have a very simply scene that I am trying to use to understand how to work with direction, especially after an object has changed its rotation. Consisting of a cube and a terrain …

So

  1. When I try and move forward using this code (just a simply button click) it works -moves the cube forward…
public void ForwardArrow()
{
    Rigidbody body = GetComponentInChildren<Rigidbody>();
    body.AddForce(transform.forward * 50f);
}
  1. When I try and rotate the cube down it works, BUT seems to move the left side down?
public void TiltDown()
{
    Rigidbody body = GetComponentInChildren<Rigidbody>();
    body.AddTorque(transform.forward * 25.0f * 2.0f);
}
  1. How do I alter this code below to move the cube in the new direction it is facing?
public void ForwardArrow()
{
    Rigidbody body = GetComponentInChildren<Rigidbody>();
    body.AddForce(transform.forward * 50f);
}

AddTorque applies a rotation around the given torque axis. In your example, the code is trying to rotate the cube around the forward axis. Try using AddTorque with transform.up instead.

As @Edy has mentioned here when you are applying the torque you are applying it around the transforms forward vector (imagine an arrow sticking out the nose facing front). This is essentially going to cause your object to roll , and not to pitch like you may be expecting. if you want to lean forwards (tilt the nose up or down) you need to rotate around a vector that is perpendicular in this case transform.right would cause you to nose up or down. {stick your arms straight out and rotate around that axis}. Try modifying your Tilt() method to use transform.right, your move forward method should now be moving you in the direction of your nose.

    public void TiltDown()
    {
        Rigidbody body = GetComponentInChildren<Rigidbody>();
        body.AddTorque(transform.right * 25.0f * 2.0f);
    }