Jump to content
  • Advertisement
Sign in to follow this  
discodowney

Caluclating a characters heading

This topic is 3014 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

Im doing obstacle avoidance and i need to know a characters heading. No doubt i was supposed to be keeping track of this all along, but it hasnt come up until now. So im wondering how i work out a characters heading?

Share this post


Link to post
Share on other sites
Advertisement
How do you expect anyone to answer that? What do you know? How do you want the heading expressed? Can you post an example?

Share this post


Link to post
Share on other sites
yeah sorry.

Okay. Its all in 3D space, so for example. If i have a character at (0,0,0) and they are moving to (10,0,0). The velocity is worked out from a path following algorithm. I also know the characters maxSpeed and acceleration, but i dont imagine theyll have any influence. So can the heading be caluclated from this?

Share this post


Link to post
Share on other sites
Quote:
Okay. Its all in 3D space, so for example. If i have a character at (0,0,0) and they are moving to (10,0,0). The velocity is worked out from a path following algorithm. I also know the characters maxSpeed and acceleration, but i dont imagine theyll have any influence. So can the heading be caluclated from this?
By 'heading', do you mean a single angle that represents the direction in which the object is facing?

If so, an object in a fully 3-d environment doesn't really have a heading, per se. What do you need the heading for? I'd be willing to bet that whatever it is, it can be done just as easily using (e.g.) the object's local coordinate frame instead.

Share this post


Link to post
Share on other sites
Where im gonna use it is in obstacle avoidance. When an obstacle is found it gets the difference between the character and obstacles position. then gets a perpedicular vector from this and the heading so it will move towards that direction away from the obstacle. Ive also seen the heading used in mehtods getting character to rotate to face a specific position.

Share this post


Link to post
Share on other sites
Is this basically a 2-d simulation? That is, even though the environment is 3-d (if only graphically), do the agents always move within a plane and maintain a fixed 'up' vector?

Share this post


Link to post
Share on other sites
Quote:
When an obstacle is found it gets the difference between the character and obstacles position. then gets a perpedicular vector from this and the heading so it will move towards that direction away from the obstacle. Ive also seen the heading used in mehtods getting character to rotate to face a specific position.
Although I didn't quite follow this, I'm still not convinced that you actually need the heading in angle form (which I assume is what you're looking for).

However, since the up vector is fixed, you should be able to compute a heading angle using an 'atan2' function (assuming you have one available) and the object's current velocity or forward direction vector. As an example, if +z is up, the code might look something like this:
float heading = atan2(forward.y, forward.x);

Share this post


Link to post
Share on other sites
Quote:
Sorry, the heading in the code samples ive been looking at is in Vector form not angle.
Hm. Well, you must know something about the object's orientation, right? At the very least, you must have a matrix or some angles or something - otherwise you wouldn't be able to render the object very easily.

How is the object's orientation represented? Whatever representation you're using, you should be able to derive a 'heading' vector (by which I assume you mean a forward direction vector) from it.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!