Problems with Create with Code Lesson 3.3 Don't Just Stand There

Hi!

I´m going through the “Create with Code Lesson 3.3 Don’t Just Stand There” and i have a problem.

When applying the jump animation, the player is not jumping on the spot, but is actually jumping forward, leading to the player leaving the frame after a couple of jumps.

I have not been tinkering with the animation, other than what is part of the lesson.

Thanks!

/John

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{

    private Rigidbody playerRb;
    private Animator playerAnim;
    private float jumpForce = 800;
    public float gravityModifier;
    public bool isOnGround = true;
    public bool gameOver = false;

    // Start is called before the first frame update
    void Start()
    {
        playerRb = GetComponent<Rigidbody>();

        playerAnim = GetComponent<Animator>();

        //Physics.gravity = gravityModifier * Physics.gravity;
        Physics.gravity *= gravityModifier;

    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey(KeyCode.Space) && isOnGround && !gameOver)
        {
            playerRb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
            playerAnim.SetTrigger("Jump_trig");
            isOnGround = false;
        }
    }

    private void OnCollisionEnter(Collision collision)
    {
       
        //Ser om objektet man kolliderar med har taggen "Ground" eller "Obstacle"
        if (collision.gameObject.CompareTag("Ground"))
        {
            isOnGround = true;
        } else if (collision.gameObject.CompareTag("Obstacle"))
        {
            playerAnim.SetBool("Death_b", true);
            playerAnim.SetInteger("DeathType_int", 1);
            gameOver = true;
            Debug.Log("Game over");
        }
    }
}
2 Likes

Hey,

I just hat the exact same problem as you, but found the solution here:

You need to disable “Apply Root Motion” on the Player by clicking on it in the hierachy and unticking the checkbox in the Animator Component.

Hope this helps :slight_smile:

6 Likes

Had the same problem, disabling Apply Root Motion helped!