Hey I created a player that when you click A and D it will move in the respective direction and also turn but I don’t know how to get him to stop turning when he is facing in the correct direction. This is what I have so far:
using UnityEngine;
using System.Collections;
public class PlatformControls : MonoBehaviour
{
private Rigidbody rb;
public float speed;
public float turnSpeed = 0.5f;
public float jump;
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector2 movement = new Vector2(moveHorizontal, 0.0f);
transform.Rotate(0, moveHorizontal, 0);
var x = Input.GetAxis("Horizontal") * Time.deltaTime * 150.0f;
transform.Rotate(0, x, 0);
rb.velocity = (movement * speed);
if (Input.GetKey(KeyCode.W))
{
Vector2 jump = new Vector2(0.0f, moveVertical);
rb.velocity = (jump * speed);
}
}
}
Any Help is appreciated!