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. Dismiss Notice

how to make an object move forward based on it's rotation (C#)

Discussion in 'Scripting' started by Lenticularic, Jul 17, 2021.

  1. Lenticularic

    Lenticularic

    Joined:
    Nov 16, 2020
    Posts:
    46
    title says it all,
    how do I make an object move forward based on it's rotation with a script? (unity 2D)

    I can't find any tutorials, I don't know if I phrased this right.
     
  2. Johan_Liebert123

    Johan_Liebert123

    Joined:
    Apr 15, 2021
    Posts:
    474
    I don't understand what you mean by, "I want to make an object move forwards based on it's rotation." Do you want to move it in the direction it's facing?
     
  3. Lenticularic

    Lenticularic

    Joined:
    Nov 16, 2020
    Posts:
    46
    yes, I want to move it in the direction it's facing
     
  4. DrHerringbone

    DrHerringbone

    Joined:
    Jan 3, 2021
    Posts:
    13
  5. wileyjerkins

    wileyjerkins

    Joined:
    Oct 13, 2017
    Posts:
    77
    Create a sphere, give it a rigidbody, apply force. It will roll. I posted a script today that does this using the new input system.
     
  6. Emolk

    Emolk

    Joined:
    Feb 11, 2014
    Posts:
    241
  7. vargata

    vargata

    Joined:
    Nov 26, 2013
    Posts:
    120
    I think its too early for you to try unity's bonkered physics. just keep adding
    transform.position += transform.forward * speed * time.deltatime;
    no need of rigid body. you can make up acceleration and deceleration too easily by increasing speed while forward button is held down and decrease speed until zero when the button is released. if you need it
    wander into rigidbody waters later