Physics for a character running

Official forum for the Chipmunk2D Physics Library.
Post Reply
Youx
Posts: 3
Joined: Wed Jan 02, 2008 5:51 am
Contact:

Physics for a character running

Post by Youx »

Hi everyone

I was wondering if anyone had a good idea about a good way to simulate (really boldly) a human running, like a character sprite for a game, in chipmunk.

What I am doing right now is :
world
* gravity = 400 downward

ground
static body
* mass = inf
* inertia = inf
with a segment shape
* friction (u) = 1.0

man
a body
* mass = 1.0
* inertia = 1000
with a square shape (-50,-50 -> 50,50)
* friction (u) = 0.2

When a key is pressed to run, I apply a force of 100 to the right
When a key is pressed to jump, I apply an impulse of 200 upward

So far, it works (after a lot of tries), but not exactly like I want :
- Acceleration and deceleration are quite low (you have to keep the run button on for a long time to get it "running", and to have it "stop" once the button is released)
- I don't think it reaches a "peak" speed like it should (if I keep pressing on the run button, it gets faster and faster)

I am quite new to this, and not really good at physics (been a long time), but I am really interested if someone has any suggestion to achieve this (quick acceleration to reach a peak speed, quick deceleration to stop)

Thanks
dc443
Posts: 20
Joined: Sun Dec 02, 2007 3:54 am
Contact:

Re: Physics for a character running

Post by dc443 »

You probably don't want to just apply a constant force because that simply means the object's velocity will get faster and faster. You could apply a drag force in the opposite direction which is proportional to the speed, or speed squared or something like that, and it will then reach a maximum velocity.

Your friction of 0.2 on the guy seems a bit small if you want the friction to cause him to stop quickly.
lucas
Posts: 54
Joined: Wed Sep 26, 2007 2:34 am
Contact:

Re: Physics for a character running

Post by lucas »

Unless you want ragdoll, make the character a square when running, and change to a shape on collisions.
Tangame - a tangram puzzle game with physics.
http://code.google.com/p/tangame/
Youx
Posts: 3
Joined: Wed Jan 02, 2008 5:51 am
Contact:

Re: Physics for a character running

Post by Youx »

Ok, thanks for the advices, it was really useful!!
I changed a few things :
- I increased the friction (to 0.95), and increased the force applied (1000 instead of 100), so now it accelerates and stops much quicklier.
- I also substracted 2 times the speed when moving, so now it reaches a nice peak speed.

But even though all this works fine now, I am running into a completely different problem now :
When I make the character jump (while running), when it reaches the floor, the square starts "rolling", probably because of friction or something : ->jumpy
I thought of replacing the square by a circle, but there is not enough friction on a circle to make it stop, so I get an "ice-skating" character.
I am going to try flattening the square into a rectangle, maybe lowering its center of gravity like this will help? Or maybe I should try to increase the mass of the square?
Android_X
Posts: 18
Joined: Wed Oct 31, 2007 7:55 pm
Contact:

Re: Physics for a character running

Post by Android_X »

If you want the rigid body to never rotate by itself just set its inertia to INFINITY.
Regards, AX
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Physics for a character running

Post by slembcke »

Seriously, you should look at surface velocities. Don't use basic forces to move your character. It will make walking on platforms and other interesting bit in your game trivial.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Youx
Posts: 3
Joined: Wed Jan 02, 2008 5:51 am
Contact:

Re: Physics for a character running

Post by Youx »

Ok thanks, I'll take a look at that :)
Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests