what to do after a collision has occoured

Started by
7 comments, last by fguihen 19 years, 3 months ago
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?
I currently only use c# and directX9, in case its relivant and i didnt mention it in the post
Advertisement
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
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).
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?
I currently only use c# and directX9, in case its relivant and i didnt mention it in the post
Quote:Original post by fguihen
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?


What is your wall? a Polygon, a box?
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
I currently only use c# and directX9, in case its relivant and i didnt mention it in the post
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.
Jetblade: an open-source 2D platforming game in the style of Metroid and Castlevania, with procedurally-generated levels
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
http://www.8ung.at/basiror/theironcross.html
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
I currently only use c# and directX9, in case its relivant and i didnt mention it in the post

This topic is closed to new replies.

Advertisement