I’m making a top down puzzle game. You can move the character up down left and right.
The character is moved by changing its velocity (rigidbody.velocity = movement).
The only thing I need to do now is rotate him, I’ve tried LookAt, LookRotation, transform.rotation and SetLookRotation but they all seem to bug out or just not work at all. I just want the characters Y rotation to change based on its velocity, if its moving up, then rotate his Y in that direction.
My Code:
public float speed = 6f;
public GameObject camTarget;
Vector3 movement;
Rigidbody playerRigidbody;
void Awake(){
playerRigidbody = GetComponent<Rigidbody> ();
}
void FixedUpdate(){
if(Input.GetKeyDown(KeyCode.E)){
CameraShake();
}
float h = Input.GetAxisRaw ("Horizontal");
float v = Input.GetAxisRaw ("Vertical");
Move (h, v);
}
void Move(float h, float v){
movement.Set (h, 0f, v);
movement = movement.normalized * speed * Time.deltaTime;
playerRigidbody.velocity = movement;
}
void CameraShake(){
Camera.main.transform.GetComponent<Animation> ().Play ("CameraDarken");
camTarget.GetComponent<Animation> ().Play ("CameraShake");
}
My Character:
Any help at all would be greatly appreciated.