- Home /
Rotation math question: car movement on a cylinder
Hi, I'm trying to make a small game, but I'm stuck with a problem. The game will involve a car driving around on a cylinder.
I have a gameobject with car movement on a flat surface, with proper rotation and all that. Then I'm projecting it onto a cylinder. Only problem is to combine the cars rotation with the angle of the cylinders surface. How do I calculate that?
Right now I only use:
Quaternion.Euler(Mathf.cos(angle*rad)*speed, 0f, Mathf.sin(angle*rad)*speed)
to get the proper rotation before placing it on the cylinder.
Please help!
Given an object, if you want to align it's up vector with a surface, the typical solution is:
transform.rotation = Quaternion.FromToRotation(transform.up, normal) * transform.rotation;
...where 'normal' is the normal of the surface. I don't know how you've structured your game, so I cannot tell you the best way to get the normal. Given a position on the surface of the cylinder, you can just subtract the the position of the cylinder to get the normal.