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 trialMichael North
2,561 PointsCode is right but game won't work
Ain my game development i have checked my code multiple times and found no errors. But the thing is the game will not move the frog, and there are no errors overall, please help
Michael North
2,561 Pointsusing System.Collections; using System.Collections.Generic; using UnityEngine;
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 GameObject
playerAnimator = GetComponent<Animator> ();
playerRigidbody = GetComponent<Rigidbody> ();
}
// Update is called once per frame
void Update () {
// Gather input from the keyboard
moveHorizontal = Input.GetAxisRaw ("Horizontal");
moveVertical = Input.GetAxisRaw ("Vertical");
movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
}
void Fixedupdate () {
// If the player's movement vector doesnt equal 0 ...
if (movement != Vector3.zero) {
//...Then create a target rotation based on movement Vector
Quaternion targetRotation = Quaternion.LookRotation (movement, Vector3.up);
//...and create another rotation that moves from the current rotation to the target rotaion
Quaternion newRotation = Quaternion.Lerp (playerRigidbody.rotation, targetRotation,turningSpeed * Time.deltaTime);
//...and change the players rotation to the new incremental rotation
playerRigidbody.MoveRotation (newRotation);
//... then play the jump animation
playerAnimator.SetFloat ("Speed", 3f);
} else {
//...Otherwise dont play movement animation
playerAnimator.SetFloat ("Speed", 0f);
}
}
}
Alexander Davison
65,469 PointsAlexander Davison
65,469 PointsIn programming, code may not cause errors, but may cause Semantic Errors which are errors that are harder to find. These don't show up in the Console. For example, maybe in our code somewhere we did
a + 1
instead ofb + 1
. The code doesn't cause an error, but you get unexpected output because you are writing code that doesn't do what you told it to do.Please provide your code, because it might have some Semantic Errors.