Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm making a small lockpicking simulator. Obviously I'll need the pick to not pass through the lock, and I'll need the pins to move when you tap or push them with the pick.

Here's what I have so far, just to give you an idea.

http://megaswf.com/serve/2433982

As you can see, the collision detection is pixel perfect. I've looked into a couple of different ways of doing collision response, but it seems like such a vast and complicated field. Any time I come up with a possible solution I start noticing flaws like what would happen if more than two objects collided and so on.

I've looked into physics engines like Box2D, but it seems like such overkill considering the, I think, simple nature of the game I'm trying to make. I don't like the idea of using a huge library that I don't even begin to understand just because I can't figure out how to do collision response.

But I just don't know where to begin. Maybe I will have to use a library. If anyone with experience could, based on that demo and what I'm trying to do, suggest a course of action, I'd really appreciate it.

share|improve this question

2 Answers 2

You could use a simple Move-Collision-Rollback approach.

  1. Move the object by dt * direction.
  2. Check collision, if so, go back 1.
share|improve this answer

I think you've already pinned down the answer in your question: a physics engine would be overkill for this. The fact that your colliding objects are (mostly) constrained to a single direction of motion and that they're trapped on their sides makes this a complicated situation for most out-of-the-box physics engines, and a nightmare to try and do your own physically-accurate collision response code for. So why worry about physics at all? Hack it!

More precisely, the expectation for a game like this isn't to have the physics be accurate, it's to have the physics feel good. I think the step you need to take from here isn't to code your physics, but to design it: 'what do I want the responses of the pins to be when the pick is in the right range, and what do I want them to be when they're being pressed off-center by the pick? How do I want them to slide back down when the pick releases, and should they slide back at all?' Decide how you want the response to work for these circumstances, and then code your contact response to match your expectations.

This isn't the approach I'd recommend for every problem; in particular, accurate physics and simulated (rather than explicitly designed) systems tend to be a good source of unexpected emergent behavior (occasionally for worse, but mostly for the better). But that's not really what you're looking for for a project like this; here, the most important design element is fidelity to the experience, and you'll almost always get a higher level of fidelity with a custom design than by trying to tweak your simulation to match the target.

share|improve this answer

Your Answer

 
discard

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.