- Home /
(C#) Movement Rotation Script not Working!
Hey unity answers! Recently I've been working on a movement script that will make the player face the direction that they are moving (kinda like Animal Crossing?). But for some reason, the player stay's statically facing forward! Here's my script as it is: using UnityEngine; using System.Collections;
public class PlayerController : MonoBehaviour {
public float moveSpeed = 5f;
public float turnSpeed = 50f;
public Transform orbit;
public Rigidbody rb;
void Start() {
}
// Update is called once per frame
void Update () {
transform.eulerAngles = new Vector3(rb.velocity[0], rb.velocity[1], rb.velocity[2]);
if (Input.GetKey (KeyCode.W))
transform.Translate (orbit.transform.forward * moveSpeed * Time.deltaTime);
if (Input.GetKey (KeyCode.S))
transform.Translate (-orbit.transform.forward * moveSpeed * Time.deltaTime);
if (Input.GetKey (KeyCode.A))
transform.Translate (-orbit.transform.right * moveSpeed * Time.deltaTime);
if (Input.GetKey (KeyCode.D))
transform.Translate (orbit.transform.right * moveSpeed * Time.deltaTime);
}
}
Orbit is a sphere parenting the camera, and RB is the player's rigidbody. Thanks so much for ya'lls help! ~Nate (@ChefSpooky) (@a_game_by_nate)
Your answer
Follow this Question
Related Questions
Why does my character keep sliding around? Help! (Rigid Body) 1 Answer
Making a bubble level (not a game but work tool) 1 Answer
Question about movement with Rigidbody | Diagnol movement going faster 2 Answers
How to make a Grid movement (tile per tile) 1 Answer
How to make moving backwards slower than moving forwards 1 Answer