# what to do after a collision has occoured

This topic is 5063 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

not sure if this belongs here or in maths and physics but il try here.i have been using avros algorithm to check if my charachter, who has a bounding sphere, colides with a wall that has a axis aligned bounding box. my next problem is causing quite a bit of trouble. how do i make my charachter react realistically to the colission. he's moving at a constant speed, in a specific direction. how would he decide which way to turn when a collision happens. what i mean is this: my charachter colides with a wall. how does he pick to turn left or right? lets say he turns left, but theres a wall in his way also, does he keep turning left until he has a path with no obstacles? also, how would i do it fluently, by making him slow down as he approaches the obstacle and then turn?

##### Share on other sites
Well what i would do is work out the angle between the direction he is travelling before collision and the plane of the surface at the point of collision. Then depending on which way the angle points get him to turn.

Yeha theoretically he should keep going until he stops hitting stuff.

ace

##### Share on other sites
Is it the player you are controlling or is it an NPC?

1. If it is the player then just project the character out of the wall along the collision normal and you can slide along the wall.

2. If it is an NPC: you need to do some path-finding. Look into the A* algorithm. If you have a polygonal world you should look into generating a graph where each node represents a legal position for a character (not into a wall) and connect the nodes with edges on which a character can walk (not through a wall).

As a direct response to your question, you can project the character out of the wall and determine if he went left or right (using the dot product with the a vector perpendicular to the velocity and the up-vector). The check whether this angle is positive or negative (left or right).

##### Share on other sites
its the pc. how do i work out the angle between direction of travel and the wall plane.? for that matter, how do i get the plane of the wall?i have the axis aligned bounding box of the wall. can the plane be worked out from there?

##### Share on other sites
Quote:
 Original post by fguihenits the pc. how do i work out the angle between direction of travel and the wall plane.? for that matter, how do i get the plane of the wall?i have the axis aligned bounding box of the wall. can the plane be worked out from there?

What is your wall? a Polygon, a box?

##### Share on other sites
the wall is an axis aligned bounding box, if that helps. it is a mesh i created in 3D studio max, and imported it into directX as a .x file. my charachter is the same, except he uses a bounding sphere for collision detection

##### Share on other sites
Draw the triangle consisting of the player's movement vector and the wall, and find out what the angle of intersection is. For example, in a 2D world, if the player is moving at vector (1, 1) and intersects a wall along the y = 2 line, then the player's movement vector forms a 45-45-90 triangle with the wall (i.e. the angle of collision is 45 degrees). So you send the player off at a 45-degree angle away from the wall - his new movement vector is (-1, 1). More generally, you're going to need to use some trigonometry to find the angle, but it shouldn't be too hard. Remember, paper and pencils are two of the programmer's best friends. Also remember that for any given axis-aligned collision, you're only going to modify one of the components of the player's movement vector.

##### Share on other sites
Derakon: you mean the movement vector + the movement vector reflected by the plane (1,1) +(-1,1) as in your example is (0,2)

right?

is this the same the Ilici described in his post cause i didn t check this entirely but there was a article on gamasutra some time ago about sliding movement in quakeengines

##### Share on other sites
since my wall is an axis alligned bounding box, it has two vectors, max and min. from my understanding, i normalise theese, get the dot product of them and the resulting vector will be used, along with the sphere center of the charachter. what do i do with the resulting vector and the sphere center vector to find teh mirror angle of the one that i am after hitting the wall at?im not sure of trig, so im not sure if i use sin, cos or tan or atan2

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 12
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633314
• Total Posts
3011327
• ### Who's Online (See full list)

There are no registered users currently online

×