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

This frog isn't going anywhere

My amphibian antagonist dances in place like a champ but doesn't seem ready to hop into action. I'm reposting this question from elsewhere in the forum to associate it with this specific video.


When I press play to preview the game, the frog starts its idling dance. However, it does not jump when I press any of the following keys: up arrow, down arrow, right arrow, left arrow, w, a, s, or d.

Here is my code:

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);
        }
    }
}

1 Answer

John Steer-Fowler
PLUS
John Steer-Fowler
Courses Plus Student 11,734 Points

Hi Diana,

I saw your other post as well regarding this issue.

I would love to help you, and have looked carefully at your code. However, I am also fairly new to Game Development and the C# language. Although I know the basics, everything looks right with your code to me.

I would recommend going back over the video. I might be wrong, and I might have missed something, but I think the issue might lie in the Inspector in Unity, not in your code.

Hopefully someone far wiser and far more good looking than me will help you soon :D

Keep up the good work

Thanks, John. You were correct about the problem being in the inspector. I paused the video @11:40 and stared at the screen for a handsome spell to make sure my settings matched. Even though I created the PlayerMovement script from the player object inspector, it wasn't showing up as a component. (Maybe I forgot to save at some crucial point in the process?) After I reattached the script, everything worked as it should.