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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Lesson 3.1 Unity Learn - Player jump away instead of jump up

Discussion in 'Community Learning & Teaching' started by joao_redcape, Apr 17, 2021.

  1. joao_redcape

    joao_redcape

    Joined:
    Apr 14, 2021
    Posts:
    2
    Greetings,

    While following instructions of Unity Learn Unit 3 - Lesson 3.1, my player showed a weird behaviour and just jumped back spinning away instead of jump up and go down by gravity. Also when I look at Inspector, x, y and z are increasing.
    I think the problem is related to "Vector 3" part, but I can't find the cause.

    Player has gravity on and constraints are not checked. If I check constraints (except for Y), the player fly up indefinitely while Y stats on Inspector increases.

    PS: I had to recreate the scenario because Unity assets pack for this lesson got errors.

    Any idea about what is causing this Olympic movement?
    Thank you in advance.



    erro.png

    Code is below:

    public class PlayerController : MonoBehaviour
    {
    private Rigidbody playerRb;
    public float jumpForce = 10f;
    public float gravityModifier;

    // Start is called before the first frame update
    void Start()
    {
    playerRb = GetComponent<Rigidbody>();
    Physics.gravity *= gravityModifier;
    }

    // Update is called once per frame
    void Update()
    {
    if (Input.GetKeyDown(KeyCode.Z));
    {
    playerRb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
    }
    }
    }
     
  2. Valjuin

    Valjuin

    Joined:
    May 22, 2019
    Posts:
    481
    Remove the semicolon from this line:

    if (Input.GetKeyDown(KeyCode.Z));
     
  3. joao_redcape

    joao_redcape

    Joined:
    Apr 14, 2021
    Posts:
    2
    Thank you, Valjuin.

    I also found out that the axis of my project were changed and the camera too.
    So my gravity was pulling left. That made my player "fall to the left".
    Very junior mistake. =)