Physics for a character running

Official forum for the Chipmunk2D Physics Library.

Physics for a character running

Postby Youx » Wed Jan 02, 2008 6:25 am

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
Youx
 
Posts: 3
Joined: Wed Jan 02, 2008 5:51 am

Re: Physics for a character running

Postby dc443 » Wed Jan 02, 2008 4:13 pm

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.
dc443
 
Posts: 20
Joined: Sun Dec 02, 2007 3:54 am

Re: Physics for a character running

Postby lucas » Thu Jan 03, 2008 4:58 am

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/
lucas
 
Posts: 54
Joined: Wed Sep 26, 2007 2:34 am

Re: Physics for a character running

Postby Youx » Thu Jan 03, 2008 7:19 pm

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?
Youx
 
Posts: 3
Joined: Wed Jan 02, 2008 5:51 am

Re: Physics for a character running

Postby Android_X » Thu Jan 03, 2008 7:34 pm

If you want the rigid body to never rotate by itself just set its inertia to INFINITY.
Regards, AX
Android_X
 
Posts: 18
Joined: Wed Oct 31, 2007 7:55 pm

Re: Physics for a character running

Postby slembcke » Fri Jan 04, 2008 1:57 pm

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/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Physics for a character running

Postby Youx » Fri Jan 04, 2008 9:25 pm

Ok thanks, I'll take a look at that :)
Youx
 
Posts: 3
Joined: Wed Jan 02, 2008 5:51 am


Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 1 guest

cron