This project has moved and is read-only. For the latest updates, please go here.

Static body that is moved by user code?

Nov 1, 2008 at 5:37 PM
I'm looking for a way to create a vehicle that pushes physics bodies through the world.
This would require a static body (which is not affected by gravity or bodies colliding with it). However, it should affect other bodies.
I would need to move this static body in my own code. Is there something like this already implemented?

Thanks in advance,
Nov 1, 2008 at 5:46 PM
Moving a body by manually setting the position can cause a lot of trouble. You -can- do it, but there are several problems with it:

1. It can cause trouble in broad phase colliders that rely on frame coherence for optimizing performance.
2. The body you are moving, does not calculate velocity correctly. Impacting with geometries would give funny behavior.

The best way of moving a body, is by using ApplyForce() and/or ApplyImpulse() (and ApplyTorque() for rotation).

The first thought (and therefore not nessecarily the best :)) was to disable CollisionResponse on the geometry and apply impulses to other bodies manually. You would subscribe to the Collision event on the geometry object and when a collision occurs, you apply impulse to the other geometry it collides with.

Try experimenting with it.
Nov 2, 2008 at 1:33 AM
Hi Ian,

thanks for your hints. I've altered the Body code so that I can set a flag which causes a body to not react to any applied forces.
The body can be moved using a new function that sets Body.LinearVelocity bypassing Body.Force and Body._acceleration.

My current solution is not very elegant, but I feel this might be a feature which should be improved and added to the codebase.
What do you think?
Nov 2, 2008 at 2:37 AM
I might have a look at it. Can you send it to my mail with a description of usage?
Comments in code on where to look/changes and desciptions would also be nice.

By the way, I've added your patch to 2.0. I was feature complete, but I thought that creating ellipses without being able to dynamically draw them, would be pointless. Thanks for your work. Can I add your name to our list of contributors?
Nov 2, 2008 at 9:30 AM
Was wondering, what's the difference between applyforce and applyimpulse?
Nov 2, 2008 at 3:42 PM

@Lemunde: I think I've been asked this question before. I'm going to put it into the documentation as a late addition.

Basically the biggest difference between force and impulse, is that force get's applied over time while impulse instantly changes the velocity.
Force is used to accelerate the mass while impulse is used to change its velocity.


If you need your character to jump, you would use ApplyImpulse(). Because it should happen in one moment. If you are running your game at a variable timestep (not recommended) you will also make the character jump the same height every time.

A rocket on the other hand, applies it force over time. Therefore you need ApplyForce() because it accelerates over time.

Nov 3, 2008 at 1:46 AM
Ok, thanks.  I had a feeling that's what it did but I didn't know for sure.  That's going to come in handy for a project I'm working on.  Just one more question:  Could this work for setting the velocity of an object manually?  I've had some trouble in the past with trying to instantly bring an object to a full stop.  Something about the velocity being read-only.  I think I could do it by reversing it's move direction and matching the applyimpulse to it's velocity.  I guess my question is are the impulse values relative to the velocity values?  Like if from a full stop I applied an impulse of 10, would it's velocity be 10?
Nov 3, 2008 at 10:43 AM
Yes, if you apply an impulse vector of 10, it would have a linear velocity of 10. If you apply a force of 100 (in farseer) in 10 timessteps, you will have a velocity of 10.

In 2.0 the LinearVelocity property is read/write.

Well, you could set the velocity to 0,0. Another oppertunity is using drag. (LinearDragCofficient). Depending on your preferences though.