- Home /
Question by
inspired997 · Mar 21, 2020 at 11:43 PM ·
unity 5rotationcar
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 (to go back to center) along the cylinder and not get stuck to the left or right.
Reminder: It's on cylinder and i do need a code, Thanks.
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