In my three.js game project, I am developing cars that move in different directions based on their y-rotation angle. For instance, a rotation of 90 degrees. To move them forward, I use the object.translateZ()
method, but I am facing an issue.
Utilizing physijs for car simulation, collisions between cars can alter their y-rotation, requiring them to gradually return to their original rotation as if they are maneuvering back onto the road after a crash. Without this adjustment, the city in my game becomes very chaotic.
Below is a snippet of the code I am currently using:
var targetRotation = 90
var rotation = car.mesh.rotation.y * 180 / Math.PI //converting to degrees
My goal is to implement a method to smoothly transition the car's rotation towards the target rotation angle.
Any assistance would be greatly appreciated! (Ideally, a function would be the perfect solution)