Rotate Object To Unit Vector Direction

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

Recommended Posts

Good evening!

I am trying to rotate an object so it gets the alignment of the ground triangle.
What I've got is the position of my object, the normal of the triangle and a direction vector of my object.

I thought it might be a good idea to get the xyz rotation angles of the normal (vec1). I tried this by setting the x value of the normal to zero (vec2). by calculating the dot product of original normal vec1 and the vec2 (with x = 0) I thought I might get the corresponding rotation. After doing this I thought I'd have the xyz rotation which I just could apply to my object.

Well obviously it doesn't work this way (at least not in my tests )
Can somebody give me a hint where I'm thinking wrong or whats the usual way of doing this?

Thanks!
Zerd

Share on other sites
This has been discussed quite a bit in the past - try searching for e.g. 'align with vector', 'align with normal', 'align vehicle terrain', and similar phrases and you should find some good references.

A couple of hints though. First, you don't want to use Euler angles for this. Second, a fairly common approach is to apply a relative 'corrective' rotation each update to align the object's 'up' vector with the surface normal.

Share on other sites

This has been discussed quite a bit in the past - try searching for e.g. 'align with vector', 'align with normal', 'align vehicle terrain', and similar phrases and you should find some good references.

A couple of hints though. First, you don't want to use Euler angles for this. Second, a fairly common approach is to apply a relative 'corrective' rotation each update to align the object's 'up' vector with the surface normal.

Thx for your fast respond! I found an answer to my question.
Sorry that I didn't find a solution before, but I had trouble finding the right search parameter, I'm not nativ english speaking.

For the record, this seems like a good solution for this needs: http://www.gamedev.net/topic/177004-following-high-polygon-terrain/page__view__findpost__p__2300386

Thanks again!
Zerd

1. 1
2. 2
3. 3
Rutin
20
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• Forum Statistics

• Total Topics
633656
• Total Posts
3013192
×