Hello, I’m having some issues working out how to solve this problem:
My game is relatively simple at the moment, a cube travels along a track. However this track is slightly bent (which is necessary). It is cylindrical, so the player is able to move sideways around the track, with local gravity.
As the player moves forwards, they follow the black line, this is due to the slight bend. However what I’d like instead is for the player to generally follow the direction of the track as they move forward (i.e. the white line instead). I’ve realised that one solution to this would be simply if the player rotated on it’s local Y axis to face the same direction (+some offset rotation) as the underlying face that it is in contact with, which as I understand could use a raycast.
I’ve not had any luck getting this to work using something like the following:
if (Physics.Raycast(ray, out hit))
{
transform.rotation = Quaternion.LookRotation(new Vector3(hit.point.x, transform.position.y, hit.point.z));
}
If anyone has any ideas or solutions (I’m new to Unity), please let me know, Thank you.