Search Unity

Using transform.LookAt with rigidbody.AddRelativeTorque

Discussion in 'Scripting' started by rgeade, Jun 22, 2015.

  1. rgeade

    rgeade

    Joined:
    Jul 4, 2013
    Posts:
    3
    This is likely a simple question, but after combing through several posts, I can't find the answer. I have a football that is being thrown using physics. I added a line in the update of the football to ensure that it points in the direction it is moving.

    void Update() {
    if (!thrown || hitObject) { return; } //if not thrown yet, or hit something, stop changing the lookat
    transform.LookAt(transform.position + rigidbody.velocity);
    }

    However, I also need the ball to continue to spiral. I was doing this by adding a RelativeTorque at the throw, but LookAt, I assume overrides rotation in all 3 axis. How would I use LookAt to point the ball in the direction of movement, but still rotate the ball for a spiral as it moves through the air?