Search Unity

I need a better movement script

Discussion in 'Scripting' started by Malachi32, Jan 1, 2020.

  1. Malachi32

    Malachi32

    Joined:
    Dec 19, 2019
    Posts:
    9
    I'm making a 2d platformer in 3D mode, it's part of the work requirements so i don't have much choice, but the problem i currently have is that my script has the player liable to get knocked off when jumping from platform to platform and then plummeting but if it does manage to stay on the platform it will move on the local axis rather than the global.

    My movement code is currently this
    Code (CSharp):
    1. private float horizontInput;
    2.  
    3. void Update()
    4. {
    5. horizontInput= Input.GetAxis("Horizontal");
    6. transform.Translate(Vector3.forward *Time.deltaTime * playerSpeed * horizontInput);
    7. }
    8.  
     
  2. adi7b9

    adi7b9

    Joined:
    Feb 22, 2015
    Posts:
    181
  3. Madgvox

    Madgvox

    Joined:
    Apr 13, 2014
    Posts:
    1,317
    Transform.Translate
    moves the object on its local axis by default. You can pass in the optional second parameter and specify it as
    Space.World
    to move the object along the world axis.

    I'm not sure what you mean by this. Can you elaborate?
     
  4. Malachi32

    Malachi32

    Joined:
    Dec 19, 2019
    Posts:
    9
    It's that if the player hits a higher platform than its current position it can get knocked out of the game and i'd have to reset the test.
     
  5. Malachi32

    Malachi32

    Joined:
    Dec 19, 2019
    Posts:
    9