Advertisement

Velocities in the same/opposite directions ...

Started by February 15, 2002 04:28 PM
0 comments, last by lOkO2 23 years ago
I''m implementing obstacle avoidance for my NPCs in a 3d FPS. They have no trouble avoiding stationary objects but I''m trying to tweak their avoidance of teammates so they don''t bump into each other. The NPCs may or not be moving in the direction they are facing (ie. they may be walking/running backwards or sideways) so I cannot use their model''s orientation angle in any calculations. I can determine if NPC joe''s position is "in front" of NPC fred''s "direction of velocity", ie. if joe is stationary fred will run into him but I need to determine if joe and fred are moving in the same or opposite directions as no avoidance is needed if fred is "following" in the same direction as joe. I know I could try to predict their collision by scaling their origin vectors by their velocity vectors over a time period but I''m looking for a simpler solution. Seems to me I could use the dot product of the 2 NPC''s velocities to determine if they are headed in the same or opposite directions but that is not working, probably due to my implimentation. I''ve searched the gamedev forums for this but didn''t find anything. Any ideas ?
If I understand your situation correctly, you already know how to test for collisions when you have one moving player and one stationary player, and you are now trying to test for collisions between two moving players.

One concept that might help you is that ''moving'' is always relative - one object is only moving because another is not. Now, you already have a solution for a moving object and a stationary one - instead of trying to come up with a different solution for two moving objects, try to see how the solution you already have can actually solve both problems! When you do your collision detection, pick one of the objects, and subtract that object''s velocity vector from *both* object''s velocity vectors. Now one object is (temporarily) stationary, and the other object is the only one moving. Relative speeds are exactly the same, but now you can apply your solution for one moving and one stationary object to every case. Then after you''ve determined whatever you need to determine (whether an NPC should change direction, etc) just restore the original velocities. This way you can avoid all kinds of special cases with moving towards/away/60 degrees from eachother, etc.

Sorry for the disorganization of this post.. it''s kind of late. Hope it helps anyway...
~riley
--Riley

This topic is closed to new replies.

Advertisement