- Home /
Tilt & Turn - Build stutter when turning
Hello everyone
New to Unity but not new to the programming world. I have the following code that I found while doing a search here (also still trying to understand what this code is really doing). this works perfectly in Unity:
public class ShipMovement : MonoBehaviour {
private float speed = 30.0f;
private float smooth = 5.0f;
private float tiltAngle = 15.5f;
private float ySpeed = 2.0f;
private float yRotation = 0;
private Rigidbody _rb;
private void Start()
{
_rb = GetComponent<Rigidbody>();
}
private void Update() {
if (Input.GetKey(KeyCode.Escape)) {
Application.Quit();
}
Vector3 moveForward = new Vector3(0, 0.0f, Input.GetAxis("Vertical") * speed);
transform.Translate(Time.deltaTime * moveForward);
var tiltAroundZ = Input.GetAxis("Horizontal") * tiltAngle;
yRotation += Input.GetAxis("Horizontal") * ySpeed;
var target = Quaternion.Euler(0.0f, yRotation, tiltAroundZ);
transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth);
}
}
The thing is, I am having the following issues:
When I run a build the ship stutters while turning but works great on Unity, what is causing this?.
I would like to use Rigidbody instead of transform but the turn also stutters, how can I figure this out.
lastly Is there a better way of doing this?
Thanks!
Comment
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Engine weight Simulation 2 Answers
Limit Rotation of Rigidbody to 45 Degrees (Handlebars on a Bicycle) 1 Answer
Rigidbody.AddForce with Raycast? 1 Answer