# Vector math to keep camera above road with twists and loops

This topic is 3415 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I can't get the math figured out to keep the camera above the road, when I hit a loop or twist in the road the camera just follow through and when the twist rotates back the camera follows again... I have my normals and am using them for the up vector but isn't help keep me above or below the road depending on the direction...

##### Share on other sites
Your post is very vague as to what it is you are trying to accomplish. I am going to make a best-effort post, but really, you need to be a lot more explicit and clear in your question so that someone can give you an answer to your question. I don't know what you mean by twist, barely know what you mean by loop, and have no clue what "follow through" means mathematically. Diagrams?

In general, in order to keep the camera above the ground, you take the point on the ground, and add a multiple by the up vector to it.
For example, if your ground is flat, and you want the camera 5 units off the ground, then you simply add the point on the ground + 5*up. In the case of Y up, you just add 5 to the Y position.

Back to the general case again. Since you are on a non-flat road, lets say that the P is the point on the road. If you are in a loop, this might be the top of the loop, or maybe somewhere on the side. You're going to have to know this point no matter what, so if you can't find that, then you need to consider solving that issue first. It is non-trivial for the case of loops and twists that make angles > 90 with the land.

Lets assume you have P, the point on the road. You also have N, the normal of the road's surface at that point P. In order to stay above the road at all times, say 'k' units, then you need P' = P + k*N, where k*N = <N.x*k, N.y*k, N.z*k>

If you are using some kind of look-at function that takes the up vector as an argument, then that will be the up vector you need.

1. 1
Rutin
21
2. 2
3. 3
JoeJ
18
4. 4
5. 5

• 13
• 38
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631714
• Total Posts
3001867
×