Question by iAmAwsum
·
Feb 08, 2017 at 09:19 PM ·
c#smoothdampclamped rotationlocaleulerangles
Spaceship steering limit
I'm making a script to control the spaceship using Rigidbody and localEulerAngles. I made steering the spaceship by using mouse, now my question is how would I limit the rotation. For example : Right now I'm smoothing out the rotation and I can still rotate for as much as my mouse space allows in a second. I want to have it so I can only rotate it 45 degrees from my spaceship's current rotation.
This is my current code :
public float mouseSensitivity;
float mouseHor;
float mouseVer;
private Vector3 velocity = Vector3.zero;
private Rigidbody rb;
private void Awake() {
rb = GetComponent<Rigidbody>();
}
private void FixedUpdate() {
mouseHor += Input.GetAxis("Mouse X") * mouseSensitivity;
mouseVer -= Input.GetAxis("Mouse Y") * mouseSensitivity;
Vector3 mouseRotation = new Vector3(mouseVer, mouseHor, 0);
Vector3 smoothMouseRotation = Vector3.SmoothDamp(Vector3.zero,
mouseRotation, ref velocity, 0.2f);
transform.localEulerAngles = smoothMouseRotation;
// MOVEMENT //
}
Comment
Your answer
Follow this Question
Related Questions
Clamping camera rotation 1 Answer
Rotation before 0 and after 360 0 Answers
Mathf.SmoothDamp problem 0 Answers