-1

I have one problem about rotating wheels, code works fine, but I need it to be smooth, and I don't have idea how to do it, what to add here in code. Any kind of help will be welcome

//Rotation - WHEELS
CurrentRotation = Horizontal * RotationSpeed * Time.deltaTime;
Wheels[4].transform.localRotation = Quaternion.Euler(Wheels[4].transform.localRotation.x, Mathf.Clamp(CurrentRotation, -MaximumRotation, MaximumRotation), Wheels[4].transform.localRotation.z);
Wheels[5].transform.localRotation = Quaternion.Euler(Wheels[5].transform.localRotation.x, Mathf.Clamp(CurrentRotation, -MaximumRotation, MaximumRotation), Wheels[5].transform.localRotation.z);

     
SGAKLS
  • 13
  • 2

1 Answers1

0

I would try to use Quaternion.Slerp. I can't type out a great long explanation as I am currently on mobile. The docs should explain it well enough.

 public float speed;
 
 void Update(){
     transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, speed*Time.deltaTime);
 }

It should smoothly rotate your object over time to the new rotation.

TEEBQNE
  • 6,104
  • 3
  • 20
  • 37
  • Glad I could help! If it solved your problem you can close the question by clicking on the arrow to the left of the answer. It let's others who have a similar issue know this is the solution that fixed it. – TEEBQNE Apr 24 '21 at 19:13