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

Build Setting problem

Discussion in '2D' started by zlxeon, Feb 7, 2021.

  1. zlxeon

    zlxeon

    Joined:
    Jan 7, 2021
    Posts:
    23
    Hello, I'm programming a jump and run in Unity. When I press Play in the scene, everything works as the player should run normally, but when I build and run on build setting at Pc and it starts, the player doesn't move anymore, I can only jump. Would need a quick answer
     
  2. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,256
    Would need to look at the movement code.

    Please provide more information when asking for help. Your post is saying I need help with no real details other than it doesn't work in a build.
     
  3. zlxeon

    zlxeon

    Joined:
    Jan 7, 2021
    Posts:
    23
    Oh sorry here is my moving script


    public float speed = 5F;

    Rigidbody2D rigidbody2D;


    void Start()
    {

    rigidbody2D = GetComponent<Rigidbody2D>();
    }


    void Update()
    {

    float moveVertical = Input.GetAxis("Vertical");
    // Wie ist die horizontale Eingabe auf der Tastatur
    float moveHorizontal = Input.GetAxis("Horizontal");

    )
    Vector3 movement = new Vector3(moveHorizontal, 0f, moveVertical);


    rigidbody2D.AddForce(movement * speed);
    }
     
  4. zlxeon

    zlxeon

    Joined:
    Jan 7, 2021
    Posts:
    23
    Here you see from the Player the boxcollider and the rigidbody
     

    Attached Files:

  5. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,256
    What platform?
     
  6. zlxeon

    zlxeon

    Joined:
    Jan 7, 2021
    Posts:
    23
    PC, Mac Linux Standalone
     
  7. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,256
    So in a build it doesn't move at all?

    Nothing seems our of the ordinary for your code, other than bracket placement but that is probably a copy and paste thing, 'cause it wouldn't even compile.

    Now either there is more going on than what you have posted or perhaps you have set something in the Player settings that would cause this, namely look at Active Input Handling under configuration in Other Settings in Player under the Project settings and make sure it says Input Manager (Old) or Both.

    Not sure what else could cause it, I've had issues before making a build and things not working, it was usually a setting somewhere or difference in platform like developing on a pc vs building for Android./iOS.
     
  8. zlxeon

    zlxeon

    Joined:
    Jan 7, 2021
    Posts:
    23
    Input Manager says Old
     
  9. zlxeon

    zlxeon

    Joined:
    Jan 7, 2021
    Posts:
    23
    i test again an in the air i can run so i move a little bit but on the floor it dont move
     
  10. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,256
    Please post you're rigidbody and collider for the player if you could.
     
  11. zlxeon

    zlxeon

    Joined:
    Jan 7, 2021
    Posts:
    23
    there right is from my player the rigidbody and collider
     

    Attached Files:

  12. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,529
    2D Physics uses Vector2 not Vector3 so XY only. You're passing in a Vector3 with the vertical in the Z component so Unity converts that to a Vector2 and you end up with Vector2(moveHorizontal, 0) i.e. no vertical. Up/Down won't work here. Use a Vector2 for 2D stuff.

    Also, if you apply a force in the "Update" callback it'll do that per-frame so your character will move faster/slower depending on frame-rate. Forces should be applied in the "FixedUpdate" callback so you get a consistent movement. I'm not going to go over that in more detail here as there are lots and lots of tutorials on physics movement.
     
    Chris-Trueman and Kottler like this.
  13. zlxeon

    zlxeon

    Joined:
    Jan 7, 2021
    Posts:
    23
    So i must change Vector 3 to Vector 2
     
  14. zlxeon

    zlxeon

    Joined:
    Jan 7, 2021
    Posts:
    23