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

Cameron Button
Cameron Button
1,084 Points

Frog does not move when I press arrow keys, stays in idle animation

Finished the basic code, when I try and preview the game the frog stays in place and is still in the Idle animation.

"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, moveHorizontal);
}

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

        playerAnimator.SetFloat("Speed", 0f);

        }
}

}"

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Sorry for the delay. I only see two things that are obviously incorrect so far. This line:

 movement = new Vector3(moveHorizontal, 0.0f, moveHorizontal);

should be this:

 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);

And your fixedupdate method should be renamed to FixedUpdate as such:

Change this:

void fixedupdate () {

To this:

void FixedUpdate () {

It seems you've accidentally sent in the move horizontal number twice and have misnamed the FixedUpdate method. Make those changes and let me know if you see a difference! :smiley:

edited for accuracy

Cameron Button
Cameron Button
1,084 Points

So I made the changes and the frog moves now, but he only moves forward. Is that correct at this stage?

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Cameron Button that depends entirely on where you are! And unfortunately, you haven't said explicitly. However, if you are at the end of this video:

https://teamtreehouse.com/library/how-to-make-a-video-game/player-input-and-cameras/move-the-player-with-animation

Then yes! Your frog should jump forward and off the screen, but nothing else will happen. Nick explains why at 12:32 in the video :smiley:

Cameron Button
Cameron Button
1,084 Points

Jennifer Nordell, THANK YOU! I hadn't moved on yet because I didn't want to pile more onto an existing problem. I really appreciate the help.