Difficulties in using chipmunk physics for sidescroller shoo

Official forum for the Chipmunk2D Physics Library.
Post Reply
tuchs
Posts: 1
Joined: Sun Oct 19, 2008 4:41 pm
Contact:

Difficulties in using chipmunk physics for sidescroller shoo

Post by tuchs »

Hi!
I've tried to use chipmunk as the physics engine for a new (and old) project which tries to emulate the gameplay of Super Metroid. ( http://en.wikipedia.org/wiki/Super_Metroid , also has 2 screenshots) I hope some of you know the game, as then you'll recognize how important and perfect its gameplay was.

Unfortunately, i've run into quite a number of problems during the first few day of experimenting which I'm not really able to solve by myself.
1. The original map is split into square tiles with simple geometry per tile which makes it easy to adopt by making a CPBody out of each. Walking over such an array of blocks though leads to the player getting stuck or - when using a circular player shape - makes the player "jump" up occasionally. The game requires the player to be able to walk at really fast speeds (in the original it's visualized by having the player glow and drawing several shadows of itself behind it) and the faster the player goes, the worse the "jumping" gets. The problem was mentioned in another thread before and was said to result from the engine chosing the wrong collision axis. The other solution given (the first one being the circular player shape) involved reducing some slop-value in the source (don't remember the exact name), but that didn't help much either.
2. Somewhere it was recommended to implement player movement by setting the surface velocity. This was far to sluggish for me, so I'm now using surface velocity + setting normal velocity. When the player stops, I set surface velocity to 0, but again, it's far to slow. May i increase friction >1.0 or will i have to change velocity "by hand" once again?
3. Is there a way to make single objects unaffected by gravity? I'd like to have the "shoots" (mostly some kind of laser/plasma weapons) in my game to NOT follow a ballistic trajectory. Easiest way would be to increase speed to insane amounts but obviously that's not really an option.
4. Walking up slopes slows the player down, which is physically correct, of course. In the original game, though, the player was able to walk up 45° slopes with no speed loss at all. With chipmunk, the player "climbs" 1 or 2 tiles and slides back down then. Any idea how to fix this?
5. Walking down slopes (45°, again), makes the player run/jump forward, similar to walking over a cliff. This is physically nice, but i need it to player to stay on the ground and just walk further. (Changing impulse direction by 45° in an instant isn't exactly realistic for an object with mass, but there's no changing it)


I fear that keeping the player physics out of the physics engine and making it calculate just the environment and collisions may be the better choice over doing it in chipmunk as well. Is Chipmunk able to give predictions for collisons and minimum distances to objects in a given direction or does it only detect them when they've already happened?

Chipmunk, as the physics engine it is, is doing a great job nonetheless. It's super-fast and much fun to toy with. So many thanks for your work, slembcke!

Greetings, tuchs
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Difficulties in using chipmunk physics for sidescroller shoo

Post by slembcke »

Oh yes. I'm very familiar with Metroid. I've played Super Metriod all the way through at least twice, and played just about every other Metoid game as well I think.

Making a platformer is something I've always wanted to do, but haven't had time to try out in depth yet. So I can't necessarily give you super advice.

The first problem you describe is that Chipmunk objects are always allowed to overlap by a little bit. This causes issues when you have a smooth surface made from several joined line segments or other shapes. The shapes collide with the corners of these "cracks" in the level. If you are using segment shapes to form your level, you can give them a beveling radius in the newer versions of Chipmunk. I added the beveling to solve this exact problem. Because the ends of the segment are rounded instead of infinitely pointy, the effect should be much reduced even with a small radius. Things can still act strangely if you have a high velocity collision with a crack though.

Surface velocity hasn't worked out quite as well as I'd hoped. In particular, the amount of friction spikes when landing from a jump. While correct, it doesn't work well in a platformer. In a little tech demo I made, I got around this by setting the friction of the shape to 0 while in the air and setting it back to normal the frame after the player landed. It worked, but wasn't very elegant. Also, it's physically possible (and common) for the frictional coefficient to be greater than 1. On way to think of the frictional coefficient is what is the maximum slope you can put the object on before it starts to slide and lose traction. If you want to prevent the character from climbing a 45 degree slope, you would use a friction coefficient of 1. Remember that Chipmunk calculates the final coefficient of friction by multiplying the coefficients of the two shapes in contact.

An alternative to surface velocities is to put a wheel on the bottom of your character. This was discussed in another thread, and I've at least one project with a wheeled robot that used Chipmunk. It seemed to work out pretty well. If you are courageous enough to try the trunk version of the code, or patient enough until I stabilize the API, I have a new simple motor constraint that can be used to power a wheel at a constant speed using a maximum force. That would give you a nice sluggish feel to the controls when walking up hill, but not affect the top speed.

Can you leave objects unaffected by gravity? Yes. Chipmunk has allowed you to override the default integration functions for some time, but I have not documented the feature particularly well. You could easily enough make a new function that just echoed the parameters to the default function but set gravity to 0. As for using Chipmunk to process your gun shots, might not be a great idea. Chipmunk does do swept collisions (maybe never will), and you currently can't do ray queries either (probably will add someday, but I can't promise when). You might end up shooting right through enemies if you want very fast moving bullets.

Because Chipmunk tries to be fairly realistic, you'll have to round your corners if you want to prevent your character from hopping or bouncing down a ramp. You can't really get around this without resorting to hacks. You'd catch some air too if you went running full speed towards a steep downwards ramp. ;)

My last bit of advice: Don't put physics were they don't belong. Many recent games have put in physics simply because they look cool and are expected by gamers for big budget games. IMO, this can ruin a game and make it very frustrating as adding realistic physics can (ironically) make the game controls less predictable because objects can interact in more complicated ways. So if you are going to go with fancy physics, make sure the player controls stay simple and responsive. Using clever hacks to make the physics act more like the classic gameplay could get frustrating for both you and the player. Depends on how clever the hacks are. ;)
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: No registered users and 21 guests