Question by
Light_ · Jul 25, 2016 at 08:24 PM ·
rotationquaternion
Rotation resets after input
Hey guys I am trying to take the jump into Quaternians and I finally got this script to rotate nice and smooth, my problem is that after the input ( X Axis on a gamepad joystick) is released the player rotates back.
void FixedUpdate ()
{ //Inputs
// forward
if (Input.GetButton ("A"))
boardbody.AddRelativeForce (transform.forward * moveSpeed);
// slowdown
if (Input.GetButton ("B"))
boardbody.AddRelativeForce (-transform.forward * (moveSpeed / 2));
// rotation
float rotateAroundX = Input.GetAxis ("LeftStickX") * rotateSpeed;
Quaternion rotation = Quaternion.Euler (0, rotateAroundX, 0);
transform.rotation = Quaternion.Lerp (transform.rotation, rotation, Time.deltaTime);
I think I need to write a new Vector 3 but I can't figure it out.
Another thought is that I haven't set up the camera to rotate and follow the player yet. Is it possible that would solve this problem?
Any help will be greatly appreciated and I'm sorry to bug you guys!
Comment
Best Answer
Answer by Light_ · Jul 26, 2016 at 02:24 AM
I changed it up a bit but ultimately went with this bit of code here
void Rotate()
{
float rotateAroundX = Input.GetAxis ("LeftStickX") * rotateSpeed;
Quaternion rotation = Quaternion.Euler (0, rotateAroundX, 0);
boardbody.MoveRotation (boardbody.rotation * rotation);
Which is playing much nicer! Also I took the chunk out of update and replaced it with Rotate(); then created this new void.