Advertisement

Caluclating a characters heading

Started by March 16, 2010 12:34 PM
17 comments, last by Zakwayda 14 years, 8 months ago
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?
How do you expect anyone to answer that? What do you know? How do you want the heading expressed? Can you post an example?
Advertisement
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?
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.
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.
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?
Advertisement
Yes they will always have the same up vector.

[Edited by - discodowney on March 16, 2010 4:46:34 PM]
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);
Sorry, the heading in the code samples ive been looking at is in Vector form not angle.


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.

This topic is closed to new replies.

Advertisement