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

James Harris
PLUS
James Harris
Courses Plus Student 441 Points

Frog doesn't move when keys are pressed.

Getting no compile errors but here is the code just in case.

using UnityEngine; using System.Collections;

public class PlayerMovement : MonoBehaviour {

private Animator playerAnimator;
private float moveHorizontal;
private float moveVertical;
private Vector3 movement;

// Use this for initialization
void Start () {
    playerAnimator = GetComponent<Animator> ();
}

// Update is called once per frame
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);
    }
}

}

Helgi Helgason
Helgi Helgason
7,599 Points

Did you add the Animation in Animator Window and are the parameters spelled correctly?

James Harris
James Harris
Courses Plus Student 441 Points

I am unsure of what you mean by add the Animation in Animator Window. I have gone over the course so far and found no mention of that. And everything seems to be spelled correctly.

Helgi Helgason
Helgi Helgason
7,599 Points

There should be a folder called Animators in your project, open it and double click the PlayerController. Check if the parameters are also spelled Speed and click on the arrows and check the condition in the inspector. I tested your code, and in my project the frog moves forward so I can't really tell what the problem is, you could try a different version of Unity!

James Harris
James Harris
Courses Plus Student 441 Points

I see hop, idle, and the arrows in between have different speeds. What should they be set as? Hop is set to a speed of 4, idle a speed of 5, the arrow hop > idle a speed of 1, and the arrow idle > hop 0.5. I have the most up to date version of Unity right now. Would I need to downgrade to a lower version? If that is the problem then how?

3 Answers

Hello James, What exactly you try to do?, are you trying to move the animation of the frog? Or trying to move the frog around the environment? If you try to move the frog around the environment then you need a Rigidbody

James Harris
James Harris
Courses Plus Student 441 Points

Move around the environment. What do you mean by Rigidbody? Been no mention of that.

Hi James,

i see now where you are, you are taking the "Move the Player with animation" class then Nick is going to talk about the Quaternions: Quaternions are mathematical objects that represent a 3D rotation. In Unity, the Quaternion class has many useful methods and variables.

Don't be impatient to move the character around the environment and don't jump any class just follow along with nick he is going to teach you everything you need to finish your game.

And remember one step at a Time.

Cheers!, Joel

James Harris
PLUS
James Harris
Courses Plus Student 441 Points

His frog is moving around though at the end of "Move the Player with Animations". I haven't touched the next one, "Quaternions" since my frog isn't moving and I haven't skipped any sections. Are you saying that I should move onto the next step and my frog will start moving later?