Skip to main content
gamedev.net
🔒 Locked

avoidance

Started by daktaris Dec 21, 2004 at 12:05 PM 0 replies 800+ views
Original Post
daktaris
daktaris
I have a monster moving at 15 MPH towards a wall (so I have a direction vector with a magnitude). I have the wall's (plane) normal. How do I figure out what direction should he turn in to avoid the wall? I want it to look as natural as possible so I want him to turn left or right depending on the angle.
Motorherp
Motorherp
There's a few ways you could go about doing this depending on the results you want and how long you care to spend programming it. The simplest solution would be when your monster is whithin a certain proximity to the wall then take the dot product of the monster heading vector and wall normal. The magnitude of the result will tell you the angle between the wall and monster, and hence how much to turn, and the sign of the result will tell you which way to turn.

Alternatively you can have obsticles emit 'force fields'. What I mean by this is that when another object is within range the obsticle will apply forces to the object to push it away. The strength of the force is determined by how close the object is, so that ones that are far away are deflected slightly whilst those approaching with speed and get close will be deflected sharply. The force applied could even be scaled by the angle between the object heading vector and the obstacle normal so that forces are only applied to objects when they are moving towards the obstacle.

Finally, and the one that will give you the best results, is to implement some sort of path finding algorithm. Unfortunately however these aren't the easiest to code and I don't know a lot about them. If you're interested try googling for the A* algorithm which is one of the best. Else there's a good section on A* in 'Game Programming Gems 1' book.
[size="1"] [size="4"]:: SHMUP-DEV ::

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.