Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?


share|improve this question
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. – teodron May 14 '12 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?) – Sean Middleditch May 14 '12 at 15:27
up vote 1 down vote accepted

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...

share|improve this answer
And there's already good physics engines around, e.g. Box2D. – Laurent Couvidou May 14 '12 at 19:10
Yes, the last resource (and also the most evolve one) would be a physics engine... – J. C. Leitão May 14 '12 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

share|improve this answer
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. – teodron May 14 '12 at 12:32
Then how do you get out if your speed is 0 :P – AndroidXTr3meN May 14 '12 at 12:32
If your speed is 0, that means you cannot move... – AndroidXTr3meN May 14 '12 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. – teodron May 14 '12 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 – AndroidXTr3meN May 14 '12 at 12:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.