Recommended Posts

hey there!
as part of my collision detection i want to handle collision pretty much like many other games with sliding.
now i'll show you a picture
lets pretend our camera is looking at the character from above, the head is the character and the line is a wall.
its pretty easy to slide in the left part of the image since the wall is stright, all i need to do is to say "once you colide with the wall, move only on the y axis" and it works fine.
but its not dynamic, i dont want my game to be all squarish just because i am not smart enough to develop a formula to handle not so stright lines.
now the best i could do is to understand that i need to do something with the player's movement direction and the wall's 'direction', too bad i am not sure what i should do and too bad i dont know how to find the direction of the wall.
on what to do i thought about doing player's direction minus wall direction+90.
so, am i in the right direction? is my theory close to what that is actually done to make sliding? and how do i find this wall direction?
thanks in advance :)
p.s, in the picture you can see a mysterious circle with numbers on it. just wanted to explain that these numbers are the directions(in degrees) and that i use it this way.

0

Share this post

Link to post

Share on other sites

Ok, I can't put up with this I had to sign up to answer this or else I couldn't live with myself, lol.

Well first of all your interpretation is skewed, you should never say "If collided with wall only move on Y axis" thats a cheap in-efficient mess. Your so called "sliding" is just normal collision detection. Collision detection isn't a whole bunch of statements checking for every little thing, that is complete overkill and just a much harder way. The way I would suggest is how most collision detection and response works.

You check for collisions every frame, when it detects the player has gone "through" the wall, then it moves/sends your character back to the nearest point/location before the collision. The whole sliding aspect is just normally what happens with collision detection, you don't need to program it in separately.

If your confused on how to do proper collision detection, look for Bounding Box/Sphere Collision (its fairly simple) check Google and search the gamedev forums, or better yet. Check out the gamedev articles theres plenty of information there that people just neglect.

// slide the velocity along the collision plane.// basically, remove the part of the velocity vector that is along the plane normal// so the velocity is then parallel to the collision plane, hence 'sliding'. m_velocity -= collisionNormal * (m_velocity.dotProduct(collisionNormal)); }

Share this post

Link to post

Share on other sites

You basically want to find the normal to the wall's edge (ie a perpendicular line, 90 degrees from the angle of the wall) and push the player out along this normal until he's no longer inside the wall.

Share this post

Link to post

Share on other sites

Well when you throw a puck straight at a wall it Reflects the other way at the angle it was hit at, you also have to take mass of the Object, and speed into calculations, because if you through a block at a wall at 4 MPH, its obviously wont deflect accurately, what happens is when it is going slower and hits the wall its deflection ray is shortened, so say the block was thrown at 50 degree angle its not going to deflect and 50 degree it will prolly deflect into 1/3 of that, because it has more mass then speed. I am not a physicist, I am going to be learning some courses but, I hope that this helps any questions feel free to ask