Game Development Community

Rigid body slowly sliding

by Apurva Amin · in Torque Game Builder · 07/27/2006 (6:21 pm) · 7 replies

Hi,
I've tried various different things, but I can't seem to get it working. Basically, I have a simple square polygon sprite which is set as 'RIGID'. I've also got a tilemap which is a flat ground, where all the tiles are squares and have collision and physics enabled. The square polygon has a constant force applied to it so that it falls to the floor realistically. However, when it get's to the floor, it doesn't stay completly still. If I type "echo($player.getPosition())" in the console, there's a slight change everytime. The sprite also visibly changes slightly. I know this is due to the constant force, because when I turn it off, the sprite stays still. I remember this being an issue before, but does anyone have a way of fixing it? The tilemap is set to 'CLAMP' so that the player can move along it. However, I can't have the player set to clamp when there's a collision because the ground has edges the player should fall down realistically (ie like in rigid mode). Any ideas? One thing I just thought of is have each 'edge' tile trigger a callback which sets the player to RIGID mode and restarts the constant force, but this could be annoying when designing the map. Is there a sure fire way of making sure the player stays still?
Thanks

#1
07/28/2006 (11:32 am)
Have you tried calling setAtRest() to stop all movement? If so, does it start moving again after the call?

If I'm understanding you correctly, you're saying that you enabled physics on the tilemap. Is that correct? That could be adding to the problem. I've had many situations where I've had an object with a constant force drop onto a tilemap and it's always worked fine. But the difference is that I only enabled collision on the tilemap, not physics.

Is your constant force a positive Y value so it's simulating gravity or is it at some sort of angle? If it's at an angle than it will never come to rest until the object is "pinned" against another collision enabled object.
#2
07/28/2006 (11:47 am)
Hi,

I tried using setAtRest(). The problem is, since the constant force still applies, it pretty much negates that command. I noticed that the higher the constant force value, the more the object moves when it's on the floor.

Physics is enabled on the tilemap, but even when I turned it off the same thing happened.

The force is simulating gravity so it's a constant Y force. Could it be something to do with the properties? I've turned restitution to 0 and fiddled with friction values, but it doesn't seem to fix the problem.

Thanks for the reply.
#3
07/28/2006 (12:19 pm)
I was just going to suggest messing with the friction but that's hit or miss as you've obviously found.

I'm not currently on a PC that has the code for a game I created that mimics this exact functionality or else I'd just post what worked for me. I'll try to remember later today and post it as soon as I can. One thing I've noticed is that if even one physics or collision property is set improperly, it can cause wierd behavior in the whole physics system. I'm guessing that's the case here since there's no reason why it shouldn't just come to rest as soon as it lands if the surface is totally flat and the constant force is only in the Y direction.
#4
07/28/2006 (12:26 pm)
Thanks a lot Dennis. I bet (hope) it does turn out to be something trivial and an oversight on my part. *Fingers crossed*.
#5
08/15/2006 (8:17 am)
(Apologies for drudging up an old topic.. it has a problem I've recently run into)

I'm having a similar problem: I have a body that can move on slopes. The problem is when I stop moving the body, it slowly slides down the slope. This, I think, is caused by my constant gravity force. I want the body to be able to run part way up a slop and come to a stop. The gravity keeps pushing it a little bit down the slope. Even if I call setAtRest() on a collision, the gravity still mkes it move just a little.

I mean, I don't mind the sliding down slopes as much as I can't think of how to make "stairs" that you can walk up and stop in. Sliding down stairs makes no sense.

Did either of you two solve the problem or at least found a way to deal with it?
#6
08/15/2006 (8:47 am)
Well, I've decided to continue on a different project which doesn't require physics for the time being. Until this problem is updated, I can't really use it. The reason setAtRest() isn't working for you is because it only stops the object until a force is applied to it (which in this case is your constant gravity force). You could try using setPhysicsSuppress() and see if that works. Then turn it back on when the player needs to move. Another way, which is quite a hack, is to check what tile the object is on. If it's on a 'stair' tile, you could stop all constant force on it and it should stay still. But, as I say, I haven't really figured out how to stop it, so I'm working on a less physics heavy game. Still, I read in another post that GG are working on some aspects of the physics for the next release, but not much detail was given.
#7
08/15/2006 (11:00 am)
So, ideally, I can leave all the physics stuff to do its thing (which works very well while it's moving), but stop it when no inputs are being used?

I'll try that when I can.

I have another question: How do you delay the time between collision checks? My IsJumping variable is sometimes off because when I jump it catches one last collision after becoming airborn. I suspect that if I slow down the number of checks, not only will runtime performance increase, but also the number of times that my jump variable is inaccurate will drop.

I know that one of the arguments in the onCollision() method is %time, but how do I change it? Do I change %time inside my method?