i’m trying to get an object to move a certain way. it’s a spaceship i have it moving how i want it but it stutters as it moves. i want to have it point the direction that is pressed on the joystick and then the thrust button to move it forward. after the thrust is released i want it to float forward for a small distance in that direction but still be able to turn towards a different direction.
any suggestions to get rid of the stuttering?
this is the code i have on my player object:
{
public float rotationSpeed = 450;
public float accelerationForce = 10f;
private Quaternion targetRotation;
void Start ()
{
}
void Update ()
{
float acceleration = Input.GetAxis ("Thrust");
rigidbody.AddForce (transform.forward * acceleration * accelerationForce);
Vector3 input = new Vector3(Input.GetAxisRaw("Horizontal"),0,Input.GetAxisRaw("Vertical"));
if (input != Vector3.zero) {
targetRotation = Quaternion.LookRotation (input);
transform.eulerAngles = Vector3.up * Mathf.MoveTowardsAngle(transform.eulerAngles.y, targetRotation.eulerAngles.y, rotationSpeed *Time.deltaTime);
}
}
}