Moving Platforms, Liquid, All the Funky stuff

Official forum for the Chipmunk2D Physics Library.
X-0ut
Posts: 28
Joined: Tue Oct 02, 2007 5:02 am
Contact:

Re: Moving Platforms, Liquid, All the Funky stuff

Post by X-0ut »

Hi, I've got back to tinkering with this project and found I'm getting odd results using the cpBody slew function.
My platforms are happily following some splines which works great. But when something lands on a platform, it seems to slide off of it as if there is some force pushing it off.

Code: Select all

body->p  = newpos;
cpBodyUpdatePosition(body, TIME_STEP);
cpBodySlew(body, newpos, TIME_STEP);
I am not sure whats causing the problem. Any feedback appreciated.
X-0ut
Posts: 28
Joined: Tue Oct 02, 2007 5:02 am
Contact:

Re: Moving Platforms, Liquid, All the Funky stuff

Post by X-0ut »

Sorry with further testing the above is incorrect.
What is actually happening is the platforms dont drag objects sitting on them along for the ride.
Is this correct behaviour? You see the platforms are not in the same space as the other objects (boxes etc).
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Moving Platforms, Liquid, All the Funky stuff

Post by slembcke »

I'm assuming that you didn't forget to set friction?

What do you mean they are in a different space? How can they even collide then? Having objects be in multiple spaces is going to be a really tricky thing to do right. I don't see why you would want to do that in this case.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
X-0ut
Posts: 28
Joined: Tue Oct 02, 2007 5:02 am
Contact:

Re: Moving Platforms, Liquid, All the Funky stuff

Post by X-0ut »

The body/shapes are not in a space because I dont want them effected by gravity.
Also, because they have an infinite moment and if added to the same space as the other objects, the simulation breaks - its as if nothing collides. (this happens when two bodies with infinite mass collide)
Anyhow they do collide just fine, but they dont drag objects along with them.
For example, a plate with a cup on it. If you move the plate, the cup would still be on the plate.
What happens is like the table cloth magic trick :) The cloth gets pulled from under the cutlery, and plates etc stay on the table.

Just to clarify, the code in the earlier post was incorrect, its actaully:

Code: Select all

cpBodySlew(body, newPos, TIME_STEP);
cpBodyUpdatePosition(body, TIME_STEP);
body->p = newPos;
I have noticed, that if I remove the last line, the platforms disapear instantly - I guess they have moved offscreen very fast. (*Edit* confirmed this by slowing down the simulation)
Just to be a bit more specific about what I have done:
At the begining of the game loop, I run cpBodyUpdateVelocity for the platforms.
Next I run cpSpaceStep for all the other objects.
Lastly, I run the above code for the platforms.

I believe as you mentioned its because the platforms arent in the cpSpace, but according to the docs things like platforms shouldnt be in the space, but implemented the way I just described.
X-0ut
Posts: 28
Joined: Tue Oct 02, 2007 5:02 am
Contact:

Re: Moving Platforms, Liquid, All the Funky stuff

Post by X-0ut »

Ok I have moved the body and shapes back into the same space as the rest of the objects, by lowering the mass.
The result is still the same, objects dont "stick" ontop of the moving platforms.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Moving Platforms, Liquid, All the Funky stuff

Post by slembcke »

Ok, I'm still not sure about the particulars, but you should keep the shapes in the same space avoiding collisions with other infinite mass objects using a group or collision function. Don't add the infinite mass bodies to the space, that is correct.

On to the real problem...
I had originally thought cpBodySlew() up as part of a Ruby project. How hard could it be to port a two line function right? :oops: Obviously I never tested it...

The subtraction was switched around. It should be:

Code: Select all

cpVect delta = cpvsub(pos, body->p);
Man, I'm going to have so many moron fixes in the next release.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
X-0ut
Posts: 28
Joined: Tue Oct 02, 2007 5:02 am
Contact:

Re: Moving Platforms, Liquid, All the Funky stuff

Post by X-0ut »

Ok, the platforms now move around correctly without me having to forcefully position them.
But, any objects ontop of the platform still dont move along with it. I'm begining to think this is normal behaviour now?
Do I need to hack it myself?

EDIT* after a bit of tinkering I managed to get polygonal shapes moving along with the platforms.
What I did was manually reset all the velocity related variables before each cpSpaceStep.
Circles for obvious reasons dont move along with platforms, will have to try and hack around this somehow.
Thanks for all your help.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Moving Platforms, Liquid, All the Funky stuff

Post by slembcke »

Are you sure you are setting the friction of both the objects and platforms correctly? I've implemented platforms several times and have never had an issue. If the objects are not falling through the platform then they are having friction impulses calculated for them. The only way that they will be zero is if you have friction set to zero on one of the objects, or the surface velocity is the negation of the body velocity.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
X-0ut
Posts: 28
Joined: Tue Oct 02, 2007 5:02 am
Contact:

Re: Moving Platforms, Liquid, All the Funky stuff

Post by X-0ut »

Both objects have a friction of 1.0.
Boxes now work correctly. Circles dont, and I assume shouldnt, because it will just make them roll.
Thing is, my game character is a bike :) So kind of need to hack around a way of making it move with the platform.
Also, I noticed that if the platform is moving downwards any object ontop seems to teeter as if continually falling.
Thats another minor problem I'll need to resovle for the player case (he has an onground flag)
lucas
Posts: 54
Joined: Wed Sep 26, 2007 2:34 am
Contact:

Re: Moving Platforms, Liquid, All the Funky stuff

Post by lucas »

I think the circles don't move with the platform because there isn't any rolling friction, like mentioned in this topic. Maybe try decreasing the rotational velocity every step?
Tangame - a tangram puzzle game with physics.
http://code.google.com/p/tangame/
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests