More playable physics

Official forum for the Chipmunk2D Physics Library.

More playable physics

Postby lucas » Sat Oct 27, 2007 4:43 am

Hi,
I'm having a few problems with my game. The physics are great, but could be more playable. It's kind of hard to explain, so here is release 0.0.000001 of Stack (name not final:)): http://www.opensoft.zeeblo.com/stack.zip.
See below for the problems.

Instructions: try to stack to falling shapes. Right now there are three.

Shapes:
Small Square (mass 5)
Big Square (mass 10)
Triangle (mass 7.5)
(Paddle mass is infinite)

Keys:
Mouse - Move the paddle
Q - Gravity -5 W - Gravity +5
A - Friction -0.01 S - Friction +0.01
Z - Elasticity -0.01 X - Elasticity +0.01 (probably won't need to change this)

The defaults for gravity, friction and elasticity respectively are 200, 1 and 0. When you change one of these, it will print the value to stdout.txt, and any errors will be put in stderr.txt.

Problems:
There are two major problems, and 2 minor:

When shapes land, they are slightly crooked. After printing the value of a, the value is around 0.0001 or less. I'm guessing this is because the gravity is pushing against the paddle, which with it's infinite mass, won't budge, so it bounces back. However, I'm not sure why it does this on an angle, as it happens when both shapes are perfectly straight. A solution I can think of is rounding the angle to 3 decimal places, but it shouldn't be needed and I don't know what it would do to the underlying physics.
The second problem is that the collisions... kinda... collide to much. If you don't get it, try landing a shape, then landing shape on top of it to the side. It will bounce straight off. I think this is because all the energy is retained. What would be better is if some (or alot) of the energy is absorbed. That would make is easier and better.

The first minor problem is that when you have more than one square top each other, or you increase the friction to around 1.4, when moving left and right, instead of sliding the squares tilt to the side. Triangles don't do this.
The last problem is extremely minor, and in the end I might not even do it. Is there a way to have a constant gravity? EG. instead of having it as an acceleration, just as a constant velocity? I think you could just add a set amount to all the object's y velocity before spacing the step. Would that work?

Any ideas you have that I could put in the final game or to make the physics better, just say.

Anyway, I seem to be complaining alot, so I just want to say that chipmunk is unbelievable! I never would have been able to dream of what I was doing now without it!

Lucas

PS.
This is released under the GPL, so if you want the source, email me at lucaslevin [at] gmail [d0t] com
Tangame - a tangram puzzle game with physics.
http://code.google.com/p/tangame/
lucas
 
Posts: 54
Joined: Wed Sep 26, 2007 2:34 am

Re: More playable physics

Postby viblo » Sat Oct 27, 2007 7:25 am

It didnt start on my computer (WinXP, P4, radeon 9800). stderr.txt says "Couldn't start video: No available video device"
http://www.pymunk.org - A python library built on top of Chipmunk to let you easily get cool 2d physics in your python game/app
viblo
 
Posts: 206
Joined: Tue Aug 21, 2007 3:12 pm

Re: More playable physics

Postby slembcke » Sat Oct 27, 2007 11:09 am

Unfortunately I have no Windows computer to try this on (sounds like the one minigame on the Wii Warioware game), but it sounds like both of your problems could be solved by using more solver iterations.

The objects rotate slightly because they generate two contact points, one for each corner. Because Chipmunk uses an iterative solver, it can't solve both constraints simultaneously. It repeatedly iterates over all of the contacts in the system, solving them individually. By using more iterations, the solution converges on the ideal solution, but it will never quite be exact. So this means that depending on the order that the contact points got solved, one will be slightly overpowering the other.

A similar issue is happening that causes the boxes to bounce. Chipmunk caches the solution applied to every contact in the system and uses them as a starting point when solving the next timestep. This works great for non-moving piles of objects as the solution to the last timestep will be very close to the new timestep. Using that as a starting point and adding more iterations to it will only make it better. Now consider the case where an object has just landed. It has just had a very strong upward impulse applied to stop it's motion. During the next timestep, this strong impulse will be used as a starting point. The solver will converge on the correct solution, but it will still be slightly too big and cause the object to bounce. Landing on a stack of objects only amplifies the effect.

Anyway, again the short answer is that you want to use more solver iterations (space->iterations). I think the default is 10 or 20 iterations, but if you have a relatively simple scene go nuts and try 100 or so.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: More playable physics

Postby lucas » Sun Oct 28, 2007 3:39 am

I tried setting the iterations to 80, 100 and 1000 with no luck. I also tried zero to see if I was setting it correctly, and since there were no collisions, I assume I was. the same thing happens every time.

viblo: I don't choose the video device, so it must be something wrong with your system or SDL:(. Sorry.
Tangame - a tangram puzzle game with physics.
http://code.google.com/p/tangame/
lucas
 
Posts: 54
Joined: Wed Sep 26, 2007 2:34 am

Re: More playable physics

Postby slembcke » Sun Oct 28, 2007 10:21 am

Hmm. I'll have to give this a try on my work computer on Monday perhaps.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: More playable physics

Postby AndyKorth » Mon Oct 29, 2007 9:47 pm

lucas, I tried it on my machine and it worked just like you said... Everything that lands on the paddle is tilted by one pixel. Since you said the value of the rotation is something like 0.0001, I suspect it could be a precision problem- it's not rounding quite right.
User avatar
AndyKorth
Site Admin
 
Posts: 36
Joined: Wed Aug 15, 2007 3:56 pm

Re: More playable physics

Postby slembcke » Tue Oct 30, 2007 5:38 pm

Ah, I see what you mean now. No matter how tiny the rotation is, it's causing the graphics to get all screwy. I've had this problem myself. My solution was to draw the objects as anti-aliased. The quick and dirty solution is to turn on blending and add a single transparent pixel border around the perimeter. Let the texture filtering do the AA work. Then the tiny amounts of rotation shouldn't show up as a tilted box.

As for the reason why the triangles don't seem to want to rotate. I have no idea. I guess it looked normal-ish to me.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: More playable physics

Postby lucas » Thu Nov 01, 2007 1:44 am

It looks fine now, thanks for the advice, but what can I do to make the collisions have less energy?
Tangame - a tangram puzzle game with physics.
http://code.google.com/p/tangame/
lucas
 
Posts: 54
Joined: Wed Sep 26, 2007 2:34 am

Re: More playable physics

Postby supertommy » Thu Nov 01, 2007 3:44 am

Have you tried experimenting with the elasticity property of cpShape? I'm not sure what the default elasticity is, but maybe a rather low value would work better for you.
supertommy
 
Posts: 56
Joined: Tue Sep 11, 2007 2:30 pm

Re: More playable physics

Postby lucas » Mon Nov 05, 2007 5:37 am

supertommy wrote:Have you tried experimenting with the elasticity property of cpShape? I'm not sure what the default elasticity is, but maybe a rather low value would work better for you.

Doesn't help I'm afraid.
Tangame - a tangram puzzle game with physics.
http://code.google.com/p/tangame/
lucas
 
Posts: 54
Joined: Wed Sep 26, 2007 2:34 am

Next

Return to Chipmunk2D Physics

Who is online

Users browsing this forum: Metager [Bot] and 1 guest