Pushing/ Pulling/ Dragging a box

Topics: Developer Forum
Sep 27, 2010 at 12:39 PM
Edited Sep 27, 2010 at 12:44 PM

I've got a wheel-and-torso player character, and a box. Both with sensible frictions and torque moving the wheel.

What I'm after is a situation where the box won't move if the player runs into it, but if the player moves up to it and actively pushes/ pulls it, it glides along the floor.

I've got it set up so my player class has a DistanceJoint 'grabJoint' set at the centre of the torso, which defines its BodyB as the centre of any body if you're standing close enough and press Ctrl.

Problem is, I can't move the box.

Strikes me there's a few ways to handle this from here, notably:

 - Setting the friction to something low works well, but if there's a box on top of it, it'll slide out from under rather than taking both boxes.

 - Decreasing the mass of the box temporarily. Again, works, but isn't ideal for when it's dropped.

 - Increase torque on the wheel. This makes it juddery and unpredictable. Doesn't really move the box very much.

 

Is there a better setup for dragging objects that I'm not seeing?

Sep 28, 2010 at 7:58 AM

When you try increasing torque on the wheel, maybe try increasing the friction of the wheel as well. That might make it more stable. And maybe slow down the speed too.

You could also have the box fixed, and when the player grabs it it unfixes. However, this won't work well for when you drop it again.

The only other way I can think of is to make the player 'weak' when he try's pushing the box, and perhaps combine this with making him 'strong' when hes pulling it. 

Anything that goes against physics is difficult with Farseer! :D

Sep 28, 2010 at 1:10 PM

You can try to slightly raise the box before grabbing it:

I'm not sure what kind of joint you should use to avoid to manually move the box.

Sep 28, 2010 at 8:36 PM
Edited Sep 28, 2010 at 8:37 PM

With a combo of torque and friction, I've almost got it workable. It's not ideal, I'll probably have to come back to this at a later date. :)

Thanks for your suggestions, though. Much appreciated.

Sep 29, 2010 at 8:58 AM

Pnikosis's idea is pretty good. If you use a WeldJoint to hold the block in position, and the player is kept upright with a FixedAngleJoint (Or body.FixedRotation), then it will work without any 'hacks'. :)

But it depends on your game though. Carrying the block around might get in the way and make it harder to move than when dragging it.