Sign in to follow this  
theodore italik

confused about calculating facing vector

Recommended Posts

Hi,

I've been going through the steering behaviours chapter of Mat Buckland's AI book. In all the examples everything is moving and so the heading / facing vector is always the moving object's normalized velocity vector. In his examples he doesn't calculate a heading vector for anything with a velocity that's practically zero.

I'm trying to create a game object that I can rotate (for example like the ship in Asteroids) and then move in the direction it's facing. Is it simply a case of specifying the look at position and rotating that position by the same number of radians I'm rotating the ship? If I'm specifying a look at position should it be normalized? Or is that just for a velocity vector as you don't need the magnitude just the direction?

My brain's fairly sore at this point as I think I've confused myself by reading examples from too many websites.

Thanks,

T

Share this post


Link to post
Share on other sites
[quote name='theodore italik' timestamp='1297890969' post='4775114']
I'm trying to create a game object that I can rotate (for example like the ship in Asteroids) and then move in the direction it's facing. Is it simply a case of specifying the look at position and rotating that position by the same number of radians I'm rotating the ship? If I'm specifying a look at position should it be normalized? Or is that just for a velocity vector as you don't need the magnitude just the direction?[/quote]
It sounds like you might be confusing a 'look-at' point with a 'look' or forward vector.

You definitely don't want to use a 'look-at' point for this. It sounds like you're working in 2-d, so (e.g.) a single angle would probably be a reasonable choice for representing the object's orientation. (You could also use a unit-length vector.)

The important thing to note is that you can easily convert back and forth between representations as needed. If the speed has sufficient magnitude, you can compute the orientation either as an angle or as a coordinate basis (two orthonormal vectors) from the velocity. You can also easily build the basis from the angle, and so on. If the speed has small magnitude, you can just keep the previous orientation (in the case of steering behaviors, that is). And so on.

Share this post


Link to post
Share on other sites
[quote name='jyk' timestamp='1297929642' post='4775314']
[quote name='theodore italik' timestamp='1297890969' post='4775114']
I'm trying to create a game object that I can rotate (for example like the ship in Asteroids) and then move in the direction it's facing. Is it simply a case of specifying the look at position and rotating that position by the same number of radians I'm rotating the ship? If I'm specifying a look at position should it be normalized? Or is that just for a velocity vector as you don't need the magnitude just the direction?[/quote]
It sounds like you might be confusing a 'look-at' point with a 'look' or forward vector.

You definitely don't want to use a 'look-at' point for this. It sounds like you're working in 2-d, so (e.g.) a single angle would probably be a reasonable choice for representing the object's orientation. (You could also use a unit-length vector.)

The important thing to note is that you can easily convert back and forth between representations as needed. If the speed has sufficient magnitude, you can compute the orientation either as an angle or as a coordinate basis (two orthonormal vectors) from the velocity. You can also easily build the basis from the angle, and so on. If the speed has small magnitude, you can just keep the previous orientation (in the case of steering behaviors, that is). And so on.
[/quote]


Thanks for replying jyk, I really appreciate it. Sorry for not following up sooner but I haven't had the time.

Using your suggestion of an angle (in radians) to keep track of the rotation, I'm using the below to rotate and move the ship in the desired way. I do intend to clean up it using a Vector class but I wanted to post the code while it's working [img]http://public.gamedev.net/public/style_emoticons/default/tongue.gif[/img]


[code]
player.position.x += Math.sin(player.rotation) * speed;
player.position.y += Math.cos(player.rotation) * speed;[/code]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this