Jump to content
  • Advertisement
Sign in to follow this  
Zerd

Rotate Object To Unit Vector Direction

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!