Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Game Development How to Make a Video Game Player Input and Cameras Move the Player with Animation

Bjorn Van de Weyngaert
Bjorn Van de Weyngaert
1,297 Points

I have completed the "move the player with animation tutorial". The frog jumps but doesn't move forward. Please help?

This is the code:

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

public class PlayerMovement : MonoBehaviour {

private float moveHorizontal;
private float moveVertical;
private Vector3 movement;

void Start () {
    playerAnimator = GetComponent<Animator> ();
}
void Update () {
    moveHorizontal = Input.GetAxisRaw ("Horizontal");
    moveVertical = Input.GetAxisRaw ("Vertical");
    movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
}

void FixedUpdate () {
    if (movement != Vector3.zero) {
        playerAnimator.SetFloat ("Speed", 3f); 
    } else {
        playerAnimator.SetFloat("Speed", 0f);
    }
}

}


Any ideas why the frog jumps but does not move forward when playing the scene?

Thank you!

2 Answers

First of all: Did you miss to create the playerAnimator variable? (private Animator playerAnimator;)

And check in the inspector if the "Apply Root Motion"-checkbox of the Player's Animator component is checked. :)

This may be a workaround. I just fixed the same problem by clicking Environment asset, then Terrain, and unchecking "Terrain collider". I realized that my frog could barely move against any of the little grass or other terrain details. Strong plants.