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

Simple 2D Movement?

Discussion in 'Scripting' started by Exlerth, Sep 28, 2012.

  1. Exlerth

    Exlerth

    Joined:
    Sep 28, 2012
    Posts:
    1
    Hello!
    I've been googling around about this question for a while and I can't really find a very good answer to it.
    I have as my School-project to make a game. and we decided to make a 2D platforming/puzzle game.

    We do have some ideas and the first problem we have now is the movement.
    I've tried out Langman movement (the "upgrade" to the 2D tutorial movement). I like the Langman-script for the movement, but it's too advanced for my skills in Javascript.
    Atleast I want to understand every single thing in the script, how it works.
    I want to create my own script, atleast in my level, just something easy with movement and jump, and everything in here should be smooth, the character should also look like he turns around..

    Hopefully I'll get a good answer on a simple code or just a small tutorial about how to understand how to create my own movement-script.

    Bear in mind I'm a total newbie in this, so don't be that advanced in your talking about scripting, or using things in Unity3D. Not much is very simple for me yet^^
    Thanks in advance!
    // Exlerth
     
  2. Codetastic

    Codetastic

    Joined:
    Aug 13, 2012
    Posts:
    23
  3. Asii

    Asii

    Joined:
    Sep 28, 2012
    Posts:
    53
    so you have never programmed before or?
    well you will need to learn the basics like variables and such.

    just an very simple script.
    Code (csharp):
    1.  
    2. //here we delcare the variables
    3.  
    4. //make a new variable and its a float so it have decimals/ we have more control of how fast we want the player to move
    5. var moveSpeed : float = 10F;
    6.  
    7. //we use the update function with is going to be used every frame.
    8. function Update(){
    9.  
    10.  
    11. tranform.Translate(Input.GetAxis("Horizontal") * moveSpeed * Time.deltatime,0,0);
    12. //okay here we make the player move
    13. //okay lets see what this does
    14. //transform (gets the transform of the object/player x,y,z) then we use Translate with is a premade function for the unity engine,
    15. // okay so its saying Translate(x,y,z) so what we are doing is using the Input.GetAxis("Horizontal") where the x is in the translate function.
    16. //the Input is gonna return us 1,0,-1 if the key is being pressed or not. we * that with our moveSpeed f.eks if we hit D its gonna return us 1 and we times //that with moveSpeed then we * it with Time.deltatime with is gonna do that its the same for all no matter if you have a slow or fast computer
    17. // because remember we use the Update fucntion wich is gonna update every frame so that means it will go faster if you got a fast computer than a slow
    18. }
    19.  
    hope that helped you :)
     
  4. Lovehandles

    Lovehandles

    Joined:
    Mar 22, 2014
    Posts:
    3
    Asii, that has to be the most perfect base script I've ever seen. I've too been meandering aimlessly trying to find a script for movement that is strictly barebones. I'm a software engineer by profession, however I've never done 2D or 3D programming, so I'm at a loss when it comes to finding the basics. Kudos, my man.
     
  5. gsugarbaker

    gsugarbaker

    Joined:
    Apr 10, 2014
    Posts:
    1
    i keep getting error messages saying it is set to an instance instead of an object
     
  6. EwanMcLain

    EwanMcLain

    Joined:
    May 10, 2014
    Posts:
    1
    If you want to make a 2d platforming game I wouldn't use Unity. GameMaker: Studio is much easier to use when it comes to 2d games.
     
  7. Boonyxd

    Boonyxd

    Joined:
    May 13, 2019
    Posts:
    1
    Its says that there is a namespace error. could u possibly help me with ????
     
  8. OkeyNik

    OkeyNik

    Joined:
    Mar 14, 2017
    Posts:
    41
    My friend, link is invalid
     
  9. xenonmiii

    xenonmiii

    Joined:
    Aug 2, 2010
    Posts:
    147