Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question How can I rotate a RigidBody so it is facing the direction it is moving using velocity to move?,Rota

Discussion in 'Scripting' started by ezequielbfocuus, Jun 3, 2022.

  1. ezequielbfocuus

    ezequielbfocuus

    Joined:
    Aug 17, 2020
    Posts:
    6
    Im new to programming so Im sorry if I am making an obvious mistake (I made all this code by myself so im sorry if its a bit of a mess) but I dont know how to make my rigidbody (player) rotate to match the direction its moving (I used velocity for the movement).

    This is my code (I will upload an image):

     
  2. ezequielbfocuus

    ezequielbfocuus

    Joined:
    Aug 17, 2020
    Posts:
    6
    I will reupload the image as it is not showing up
     
  3. ezequielbfocuus

    ezequielbfocuus

    Joined:
    Aug 17, 2020
    Posts:
    6
  4. RadRedPanda

    RadRedPanda

    Joined:
    May 9, 2018
    Posts:
    1,596
    Welcome to the forum, when seeking help on this forum, instead of posting code in a hard to read image, you can instead post the code directly into your post using Code Tags, as mentioned in the top sticky of the forum.

    For your actual problem, you can use something like RotateTowards to rotate your object in steps towards your desired rotation, or you can use LookAt to directly set a target to look at in world space. You can even just directly set the rotation using a Vector3, using Quaternion.Euler.