Using the raycasting method to detect various colored strips on both sides of the track, I am able to keep my car object in position by calculating the distance. However, the issue lies in the fact that the ray always points in a constant direction in the global coordinate system and does not change with the movement or rotation of the car object. If the ray direction were in the reference frame of the car, this problem could be solved, but I am unsure how to achieve this. Currently, my code looks like this:
var ray = new THREE.RayCaster(car.position, new THREE.Vector3(-1,0,0),0,50);
The car's movement is limited to the X-Z plane.
Can anyone provide a solution to this problem?