simulating sand

Official forum for the Chipmunk2D Physics Library.
Post Reply
pentale
Posts: 3
Joined: Wed May 28, 2008 8:20 am
Contact:

simulating sand

Post by pentale »

Hi Everyone, and thank you for this little lib that I discover with some friends two days ago.
First of all, I want to apologize for my strange English : I'm French :oops:

I'm not an expert in C, so I have some issues to understand how Chipmunk works. I'm trying to simulate the effect of the sand when we try to roll with a ball in it, and I can't do that just with the e, u and surface_v in the class cpShape.
So, I tried to put a condition when there is a collision between the ball and the sand, which reduce the horizontal velocity of the ball (to simulate the fact that we can't go fast in sand and that the ball will slow down very quickly).

I used a cpCollFunc, so I added a CollisionPairFunc ( cpSpaceSetDefaultCollisionPairFunc(space, collisionFunction, NULL); ) and collisionFunction will test if the ball is in the sand, and how it will affect the velocity. (with an extra cpFloat that I add in cpBody)

It kind of works, but it is not quite what we can expect in a physical engine, to "cheat" with some tests....

Is there an other way to do that, without cheating ?

Thanks for helping !
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: simulating sand

Post by slembcke »

What you want is rolling friction. Chipmunk does not yet support rolling friction as I don't know how to do it efficiently yet.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: simulating sand

Post by slembcke »

Oh, I forgot to mention. You can fake rolling friction by damping the rotation when the ball is in sand.

Like this:

Code: Select all

if(is_in_sand)
	ball->w *= 0.9f;
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
pentale
Posts: 3
Joined: Wed May 28, 2008 8:20 am
Contact:

Re: simulating sand

Post by pentale »

Thank's for your answers !


That's what I first try, but I wasn't satisfy by this effect. Because the more we slowdown the ball, the less it will be slowed after... And I don't "see" a ball in the sand slowing down very quickly and, then, rolling very slowly... in sand...

And, I don't remember why, but I tried to affect the w, but something happened that I don't like, so I tried to affect the horizontal speed of the ball (MyBallBody->v.x), like that :

Code: Select all

if (myBodyBallvx < 0) {
	positif = -1;
	}
if (myBodyBallvx*positif > b->f) {myBall->v.x -= positif*b->f;}else{myBall->v.x = 0;}
where myBodyBallvx is, of course, MyBall->v.x, and b is the cpShape that collided with the ball. b->f is a cpFloat that I put in cpShape.h, that simulate the friction. (positif is here just to make it works whatever the sign of MyBall->v.x is.

Does it seems right to you ? - and thanks again !
Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests