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 trialE~Money Ellis
Courses Plus Student 159 PointsMy Frog still won't move! It just hop from side to side. I went back through the videos and checked my code but it still
It never has moved, beside during the idle stage.
joewode
13,803 Pointspost the code please
E~Money Ellis
Courses Plus Student 159 Pointsusing UnityEngine; using System.Collections;
public class PlayerMovement : MonoBehaviour {
private Animator playerAnimator;
private float moveHorizontal;
private float moveVertical;
private Vector3 movement;
private float turningSpeed = 20f;
private Rigidbody playerRigidbody;
// Use this for initialization
void Start () {
// gather components from the player game object
playerAnimator = GetComponent<Animator> ();
playerRigidbody = GetComponent<Rigidbody> ();
}
// Update is called once per frame
void Update () {
// gather information from keyboard
moveHorizontal = Input.GetAxisRaw ("Horizontal");
moveVertical = Input.GetAxisRaw ("Vertical");
movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
}
void fixedUpdate () {
// if player's movement vector does not equal zero...
if (movement != Vector3.zero) {
// ...then create a target rotation based on the movement vector...
Quaternion targetRotation = Quaternion.LookRotation(movement, Vector3.up);
// ...and create another roation that moves from the current location to the target rotation...
Quaternion newRotation = Quaternion.Lerp (playerRigidbody.rotation, targetRotation, turningSpeed * Time.deltaTime);
//...and change the players rotation to the 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);
}
}
}
1 Answer
Parker Busswood
20,207 PointsYour FixedUpdate method is spelled as fixedUpdate, which I imagine will cause issues with your code. Similar to the Start and Update methods, FixedUpdate is a special method that starts with an uppercase letter.
void FixedUpdate () {
// your code here
}
David Hamilton
21,522 PointsDavid Hamilton
21,522 PointsCan you provide your player movement script for us to check?