Contraints with only one body added to space

Official forum for the Chipmunk2D Physics Library.
dieterweb
Posts: 176
Joined: Fri Feb 27, 2009 7:12 am
Location: Germany
Contact:

Re: Contraints with only one body added to space

Post by dieterweb »

ok, I now set the moment and the mass of the self controlled body to INFINITY. Now it is working!! Fantastic!

One problem is left though.

When adding my self controlled body also to the space to let chipmunk handle it, I get strange problems. Seems like it has still infinite mass, as it is going through the ground. Before addinf it to the space I change the mass and the moment to correct values with the cpBodySet methods. Am I doing something I should not do? I thought these values are adjustable during runtime.

Thomas
Visit our game Blog: [url]http://zombiesmash.gamedrs.com[/url] or follow us on twitter: [url]http://twitter.com/zombiesmash[/url]
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Contraints with only one body added to space

Post by slembcke »

As long as you are using the setter functions, it should work fine as Chipmunk doesn't cache any values based on the masses or moments between calls to cpSpaceStep(). Not sure what the problem would be exactly. If it did collide with other infinite mass bodies, both of them would end up at (NaN, NaN) due to the infinite amount of mass and force involved in resolving the collision. Is it possible that you let your manually controlled object touch ground while it had infinite mass? If you did, suddenly all your other objects touching ground would either disappear or fall through the static geometry.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
dieterweb
Posts: 176
Joined: Fri Feb 27, 2009 7:12 am
Location: Germany
Contact:

Re: Contraints with only one body added to space

Post by dieterweb »

It is working better when I only set the moment to INFINITY. Thats seems to be sufficient, but I still have problems, that sometimes the objects just disappear, when I am doing this. It is working when I change both objects from self mode to chipmunk mode. But when I do this for only one, there are sometimes problems. Both are disappearing. Think I will have to investigate this further as I assume this is not enough information for you to know what is going on.

I can nearly touch the working code...

:) thomas
Visit our game Blog: [url]http://zombiesmash.gamedrs.com[/url] or follow us on twitter: [url]http://twitter.com/zombiesmash[/url]
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Contraints with only one body added to space

Post by slembcke »

Not really enough information no.

But, 99% of the time things disappearing means that they are ending up at (NaN, NaN) or (Inf, Inf). Usually this is because you have a constraint or collision between two bodies of infinite mass. Other times it happens because you have joints that are fighting each other, but in a non-infinite mass case things usually start jittering violently first.

I'd log the position/velocity of the static body and non-chipmunk controlled bodies. If they are disappearing due to a collision, you can filter those out using layers or groups easily enough.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
dieterweb
Posts: 176
Joined: Fri Feb 27, 2009 7:12 am
Location: Germany
Contact:

Re: Contraints with only one body added to space

Post by dieterweb »

Do you know where in chipmunk I have to set a breakpoint to catch cases where (NaN, NaN) or (Inf, Inf) cases happen?
Visit our game Blog: [url]http://zombiesmash.gamedrs.com[/url] or follow us on twitter: [url]http://twitter.com/zombiesmash[/url]
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Contraints with only one body added to space

Post by slembcke »

Not quite that simple unfortunately. There are a number of places where it could happen depending on the cause. You're best off adding a conditional breakpoint after the cpSpaceStep() call and tracking it back from there.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
dieterweb
Posts: 176
Joined: Fri Feb 27, 2009 7:12 am
Location: Germany
Contact:

Re: Contraints with only one body added to space

Post by dieterweb »

GOT IT!

I was calling my update function sometimes with a dt = 0 to initialize some things. Objective C does not seem to throw an excpetion or whatever when dividing by zero. I fixed that and now it seem to work perfectly.

As so often: Many thanks for your help! A donation is guaranteed when we will release our game.

Thomas
Visit our game Blog: [url]http://zombiesmash.gamedrs.com[/url] or follow us on twitter: [url]http://twitter.com/zombiesmash[/url]
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Contraints with only one body added to space

Post by slembcke »

Dividing a floating point number by zero is not an exception. It's defined such that a positive or negative finite number divided by zero will give you positive or negative infinity. If I remember my college calculus correctly, 1/0 is undefined whereas 0/0 or infinity/infinity are indeterminate. I think the reason why it's defined this was is that most limits with a denominator that approaches zero will be infinite anyway.

Chipmunk actually uses the x/0 -> infinity and x/infinity -> 0 behaviors extensively when dealing with infinite mass objects and constraint limits. This has actually come up as an issue on CPUs without dedicated FPUs. One of the normal compiler optimization flags recommended for Chipmunk is -ffast-math which disabled software checks for infinite and NaN conditions normally handled by a proper FPU.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
dieterweb
Posts: 176
Joined: Fri Feb 27, 2009 7:12 am
Location: Germany
Contact:

Re: Contraints with only one body added to space

Post by dieterweb »

Thanks for the explanation.
Visit our game Blog: [url]http://zombiesmash.gamedrs.com[/url] or follow us on twitter: [url]http://twitter.com/zombiesmash[/url]
dieterweb
Posts: 176
Joined: Fri Feb 27, 2009 7:12 am
Location: Germany
Contact:

Re: Contraints with only one body added to space

Post by dieterweb »

Let me burry up this thread :)

As you may have noticed in our beta, dangling body parts on zombies are not really stable. As faster they move the worser the dangling parts get.

e.g shoot at an arm. sometimes it will not be ripped off, but it will dangle. When this happen, we add the body for that arm to the space. Bodies of all other animated body parts are still handled by us.

The joint between the dangling part and the torso will get stable if I set inertia and mass of the torso to INFINITY. We set this back to the correct values when collisions happen. However the 1st collisions will not handled correctly as chipmunk sees still the INFINITY values.

I do not really have an idea how to work around this. Maybe I could add a flag to a body. If set chipmunk will handle the body for constraints as if it has INFINITY mass and inertia.

Do you have any other/better ideas?
Visit our game Blog: [url]http://zombiesmash.gamedrs.com[/url] or follow us on twitter: [url]http://twitter.com/zombiesmash[/url]
Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests