# Collision, then what?

I know how to check collision for example 2 spheres. But my question is how do I use the collsion response in a good way?

How do I make my character unable to walk in to the Sphere? I've got to the point where my game send a PrintLn when isCollided and it works but my character just walk through it.

How should I do?

Cheers!

• The first intuitive options: if objects moves and its position is inside the forbidden object, do not update the object's position or if the object moves inside a restricted volume, project the object outside, onto the volume's surface (perhaps adding restitution force and switching velocity to point away from the object) . If these suffice, you may try either of them.. the last one can result in a lot of jitter for irregular volumes. Commented May 14, 2012 at 12:28
• -1 as it doesn't appear that you even tried to research this. Google will find you a ton of results on basic collision detection and resolution for game physics. Also, the answers will depend a lot on information not provides, such as what behavior you want when the player collides with something (stop moving? Slide? Bounce? Push the object?) Commented May 14, 2012 at 15:27

I guess the best approach for this situation would be to use physics.

Take a look at this 2D collision.

Basically, if you want a realistic collision, you have to give a concept of mass to your objects, and, after calculating that they collided, apply the respective equations.

If objects are not spheres, then the problem is way more complicated...

• And there's already good physics engines around, e.g. Box2D. Commented May 14, 2012 at 19:10
• Yes, the last resource (and also the most evolve one) would be a physics engine... Commented May 14, 2012 at 19:51

Without knowing much about your environment, i would say: simply put your character into a not moving (aka stopped) state. That can be achieved by setting his speed to 0 or may require more complex operations :D

• there is one drawback to this approach though: say you have a sphere and point that falls under its own weight. if the point hits the sphere, then it will stick close to the sphere's surface. That can happen with a larger object: a car.. the natural behavior is to allow the object to slide against the sphere and continue falling. Your approach works for wolfenstein 3D like games (wall collisions) but you need the sliding effect even there. All in all, it's simple enough to proivde feedback. Commented May 14, 2012 at 12:32
• Then how do you get out if your speed is 0 :P Commented May 14, 2012 at 12:32
• If your speed is 0, that means you cannot move... Commented May 14, 2012 at 12:35
• @AndroidXTr3meN you need a better approach then. Reflecting velocities, adding restitution forces, friction contact forces. Going for the best means writing a physics engine. Commented May 14, 2012 at 12:37
• I've tried velocty.y and velocty.z *-1 but doesnt work. And my game doesnt have to have best physics, collision like doom Elderscrolls Arena or Wolfenstein 3D is good enough Commented May 14, 2012 at 12:42