- Home /
Question by
inspired997 · Mar 15, 2020 at 11:46 PM ·
rotationcarrotation axis
Need help with car rotaton
I am making a game where a car rotates around a cylinder. When i press left mouse click the car rotates to the left and when i press right mouse click the car rotates to the right. What i want is when i release the buttons the car should rotate to point forward along the cylinder and not get stuck to the left or right.
rotation = Input.GetAxisRaw("Horizontal");
rgb.MovePosition(rgb.position - transform.right * moveSpeed * Time.fixedDeltaTime);//move the car forward
//rotating the car
Vector3 yRot = Vector3.up * rotation * rotation_speed * Time.deltaTime;
Quaternion deltaRot = Quaternion.Euler (yRot);
Quaternion targetRot = rgb.rotation * deltaRot;
rgb.MoveRotation (Quaternion.Slerp (rgb.rotation, targetRot, 50f * Time.fixedDeltaTime));
Comment
Your answer
Follow this Question
Related Questions
How to make a steering wheel that rotates when wheels do? 0 Answers
Rotation gameobject 0 Answers
simple 360 degree Cube-rotation around y axis 2 Answers