"Collision detection + (simple) resolution only" use case

Official forum for the Chipmunk2D Physics Library.

"Collision detection + (simple) resolution only" use case

Postby JPL » Mon May 04, 2015 7:25 pm

Hello, I'm evaluating Chipmunk (via the pymunk binding) for a game I'm writing in Python, and while the API and documentation for Chipmunk/pymunk seems excellent there are some best practices I haven't been able to deduce just by reading docs, examples, and forum posts.

I'm making a top-down 2D game and my collision needs are pretty conventional, but complex enough (world and player movement are not purely tile-based) that I don't feel comfortable rolling my own. On the other hand, I do want "Mario physics", ie objects that bounce in very predictable and easy-to-tune ways, ie don't tumble or do rigid body style behaviors. So my intended usage of Chipmunk is something like:
- update game objects "manually" ie in my own game loop code
- get object collisions from chipmunk
- resolve collisions manually, setting new positions/velocities for next update

1) Is kind of setup this viable? Box2D seems to support it with "kinematic" bodies, though I haven't investigated that library much further yet as Chipmunk just struck me as higher quality in various ways. The current state of my code is that I've defined custom collision handlers ("begin" returning True, "pre solve" returning False after resolving collision - do I have that right?) for player vs static environment and player vs dynamic pushable object, but the result is buggy enough that I decided to step back and ask these questions.

2) What should the player's body/shape setup look like, ie does the player have a Body, or just a Shape? I couldn't find a precise definition of "rogue body", is it just a Body that isn't added to the global Space?

3) Between velocity, position, etc, what should I update or avoid updating from my own code? What is the meaning of Shape.surface_velocity, and how does setting this differ from setting its attached Body's velocity? I see two things in the docs that are helpful but don't make precisely clear out the best practice for my situation:
  • Modifying a body's velocity shouldn't necessarily be avoided, but applying large changes can cause strange results in the simulation. Experiment freely, but be warned.
  • Don't modify a body's position every step unless you really know what you are doing. Otherwise you're likely to get the position/velocity badly out of sync.

If any part of my current approach seems foolish, let me know, I'm in the early stages on this and it's easy to change course. I'd be fine letting Chipmunk manage the non-player objects for example. Thanks in advance!
Posts: 1
Joined: Mon May 04, 2015 1:07 pm

Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 1 guest