Page 1 of 1

Objects sliding horizontally (no friction)

Posted: Fri Oct 12, 2007 9:05 pm
by ehudros
Hi :)
I have a basic "floor" shape and body as seen in the moon buggy tutorial which is totally horizontal and flat.
Balls are bouncing from the top of the screen towards the floor with no elasticity and fricition value of 5.0.
instead of losing speed upon impact and stopping, the slide as if on an ice plain towards the left part of the screen and then hit another wall and stop. Im only guessing this has something to do with the tangent of the floor being 0 cand thus causing all sorts of pain but i think i might just be missing something obvious here.
has anyone come across such an issue? Other than that its a great library, thanks a lot!

Ehud

Re: Objects sliding horizontally (no friction)

Posted: Fri Oct 12, 2007 11:49 pm
by Michael Buckley
Dud you assign a friction value to the floor as well? As it says in the chipmunk documentation, the friction coefficient between two objects is calculated by multiplying the friction of the two objects together. Therefore, if the floor has a friction of 0.0f (which is the default), then it you will have a friction coefficient of 5.0f * 0.0f = 0.0f.

Re: Objects sliding horizontally (no friction)

Posted: Sat Oct 13, 2007 8:44 am
by ehudros
thanks for your quick reply :)
At first I thought you're right (it does make a lot of sense) but then i checked my code and was disappointed to see that I actually didnt forget to assign the floor with a friction value:


Code: Select all

cpBody* staticBody = cpBodyNew(INFINITY, INFINITY);
  cpShape *seg = cpSegmentShapeNew(staticBody, cpv(GameData->GetLeftBorder(), 0.0), 
                                                                          cpv(GameData->GetLeftBorder(), GameData->GetHeight()), 0.0f);
// friction for the floor
        	seg->u = 1.0;	
	cpSpaceAddStaticShape(space, seg);
and the object is also assigned with a value of 1...

am i missing something here?

Re: Objects sliding horizontally (no friction)

Posted: Tue Oct 16, 2007 7:23 pm
by ehudros
hmm... nobody? :(
some more research shows that the circles are actually rolling on the floor (I rendered them with the rotation values this time), and it is quite strange as I would expect them to stop after a short while if the friction value is high.
does chipmunk rely somehow on the coordinate system to be openGL based (meaning 0,0 is the center of the screen or something like that)?
Im using HGE as my game engine and everything else seems to be working fine, so i doubt i has something to do that.

the code is too complex to upload as it is, but if neccessary i can build a small demo.

Re: Objects sliding horizontally (no friction)

Posted: Tue Oct 16, 2007 7:52 pm
by maximile
Is it possible that this is expected behaviour? Because no surfaces are sliding against each other?

The way I imagine it, setting high friction values when it's a circle would just make the circle less likely to spin "against" something, rather than controlling its tendency to roll. Perhaps you'd have to change that some other way.

Re: Objects sliding horizontally (no friction)

Posted: Tue Oct 16, 2007 10:26 pm
by slembcke
Ah yes. I have not implemented rolling friction. The friction values just prevent the surfaces from slipping past each other. Rolling friction is caused by the objects deforming at the collision points and loosing energy that way. Not the same as normal friction.

Sorry about the late reply.

Re: Objects sliding horizontally (no friction)

Posted: Wed Oct 17, 2007 8:27 am
by ehudros
thanks Scott for your answer and the great engine :)
Is there a way to overcome the issue somehow? fake it?
do you have plans to get rolling friction in the engine anytime soon?

Thanks!

Re: Objects sliding horizontally (no friction)

Posted: Wed Oct 17, 2007 11:51 pm
by Michael Buckley
Well, you could set the inertial mass of the body to be INFINITY. It wouldn't roll anymore, but it should be affected by friction.

Re: Objects sliding horizontally (no friction)

Posted: Thu Oct 18, 2007 5:18 pm
by ehudros
I was able to fake rolling friction by multiplying the velocity of each ball by 0.95 every timestep.
It looks alright, and the effect is the same...

PS - I am also checking out box2d and I was wondering if someone could give me a rundown on the differences between the 2 engines?
It seems like the features are more or less the same.
thanks! :)

Re: Objects sliding horizontally (no friction)

Posted: Thu Oct 18, 2007 5:55 pm
by slembcke
ehudros wrote:I was able to fake rolling friction by multiplying the velocity of each ball by 0.95 every timestep.
It looks alright, and the effect is the same...
I did that for a proof of concept side scrolling mingolf game as well. It works OK. It's exponential instead of linear. Not particularly noticeable for slow rotating objects, but for fast rotating ones it is.
ehudros wrote:PS - I am also checking out box2d and I was wondering if someone could give me a rundown on the differences between the 2 engines?
It seems like the features are more or less the same.
thanks! :)
No idea really. I'm using Erin's impulse solver, otherwise everything else was written by me. Haven't had the time to look into it. I'd be interested to hear too. Scope out the competition in the free 2D physics scene. Must destroy!