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

Andrea Bavetta
Andrea Bavetta
2,067 Points

Frog animation fine but it does not move. Obsolete assets?

Hi there,

I have issue with moving the frog around. The animation is fine for both environment and frog jump but it does not move around. Instead it has slight random movements around its position when the buttons are pressed. I checked and rechecked the code but it seems ok. Unity have some warnings about obsolete standard assets editor and crossplatform input. How can i fix it?

Can you show me both your code and the warning/error? Thanks!

Good luck, Alex

6 Answers

Juliette Tworsey
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Juliette Tworsey
Front End Web Development Techdegree Graduate 32,425 Points

Hi Andrea,

I was stuck on this as well. Then I found this answer from another student (Jennifer Nordell) here in the forum under another post:

Try clicking on the Player prefab and note the Transform, Animator, RigidBody, and Box Collider sections.

I'm guessing that there may be no script in player prefab inspector connecting the movement of the frog to the player object. After clicking on the Player prefab (if you see no PlayerMovement script in the inspector) click add component and then in the search box at the top start typing in "PlayerMovement" . It should bring it up in a list of alternatives. Then click add component.

Try that and see if it works for you. I just worked for me.

Cheers:-)

Andrea Bavetta
Andrea Bavetta
2,067 Points

Thanks a lot Juliette! As you said the PlayerMovement script was not in the list of in the inspector. I added it as you explained but it did not fix the issue unfortunately. The script is enabled in the list, the only thing that differes compared to the videolecture is that the name of the file itself is greyed out. I think we are on the right track though

Juliette Tworsey
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Juliette Tworsey
Front End Web Development Techdegree Graduate 32,425 Points

Take a look at the code that I have in my FixedUpdate method/function:

void FixedUpdate () {
        //calculates physics
        // if the player's movement vector does not equal zero.....
        if (movement != Vector3.zero) {
            // then create a target location based on the movement vector
            Quaternion targetRotation = Quaternion.LookRotation (movement, Vector3.up);
            // and create another rotation that moves fromt he urrent rotation to the target rotation
            Quaternion newRotation = Quaternion.Lerp (playerRigidbody.rotation, targetRotation, turningSpeed * Time.deltaTime);
            // and change the player"s rotation to the new incremental rotation
            playerRigidbody.MoveRotation (newRotation);
            // then play the jump animation
            playerAnimator.SetFloat ("Speed", 3f);
        } else {
            //otherwise don't play the jump animation
            playerAnimator.SetFloat ("Speed", 0f);
        }
    }
Andrea Bavetta
Andrea Bavetta
2,067 Points

Hi Juliette! Yes it is working now! However is it normal that the frog sometimes bogs down? it looks like it finds an obstacle (like the grass for example) and cannot pass in some places. Is it the same to you as well?

Juliette Tworsey
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Juliette Tworsey
Front End Web Development Techdegree Graduate 32,425 Points

Hi Andrea. I'm glad to hear that it is working now. The only place that my frog gets stuck is when trying to hop straight into a big log.....lol... Maybe we need to figure out a way to make the frog jump higher. Other than that, everything seems to be working so far.

Andrea Bavetta
Andrea Bavetta
2,067 Points

Ahaha thank you Juliette. Well I will keep going with the course and see if i can figure it out once i get more experienced in this. So far so good though :D.

Andrea Bavetta
Andrea Bavetta
2,067 Points

Hi,

This is the code:

using UnityEngine; using System.Collections;

public class PlayerMovement : MonoBehaviour {

private Animator playerAnimator; //private means info stored in var are available only for playermovement class. 
private float moveHorizontal;
private float moveVertical;
private Vector3 movement; // Vector3 type variable is used for storing the movement vector in 3d, the direction the player is moving.

// Use this for initialization
void Start () {
    //Gather animator component from game object
    playerAnimator = GetComponent<Animator> (); //we are assigning the animation to the animator component

}

// Update is called once per frame
void Update () {
    //Gather input from keybord
    moveHorizontal = Input.GetAxisRaw("Horizontal");
    moveVertical = Input.GetAxisRaw("Vertical");

    movement = new Vector3(moveHorizontal, 0.0f, moveVertical); //0.0f says that the frog must stay on xy plane and not flying away
}

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

}

Andrea Bavetta
Andrea Bavetta
2,067 Points

I have 19 warnings but i do not know how to post the screen capture here. However many things are obsolete in camera scripts, particle systems, crossplatform input initialize, etc