Search Unity

Basic movement in Unity (script)

Discussion in 'Getting Started' started by Sanctumm1, May 11, 2020.

  1. Sanctumm1

    Sanctumm1

    Joined:
    May 28, 2018
    Posts:
    3
    SO i am REALLY confused on how to make a script for movement as there is so many different approaches

    And none seems to work :-/

    Using W,A,S,D for basic movement in a 3D world , how hard can it be...

    At this point i would have guessed there would be some basic scripts that people just use but no
    Its a jungle!

    I made a 3d World

    Made a game object of 7 components

    Now i just want to controle it (its a car)

    So how to write a basic script for movement where W,A,S,D is used. And where can i learn it? rather just focus on one learning curve than a bounch of different ways ;-(

    btw am totally newb
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    There are as many different ways to move as there are developers. But, try something like this.

    Code (CSharp):
    1. public class BasicMover : MonoBehaviour {
    2.     void Update() {
    3.         transform.position += transform.forward * Input.GetAxis("Vertical");
    4.     }
    5. }
    6.  
    This should get you forward/backward movement; now see if you can add left/right movement too. Take it one step at a time and you'll get there!
     
    Ryiah likes this.
  3. ProntName

    ProntName

    Joined:
    Apr 27, 2020
    Posts:
    15
    For a good place to start, check out this tutorial from Unity Learn. It is a good introduction to how to get movement working (it’s 2D, but the same concepts apply to 3D, in 3D you just have to consider the z axis as well).