Jump to content
  • Advertisement
Sign in to follow this  
fguihen

what to do after a collision has occoured

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
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

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
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?

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!