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

Farseer in Game Editor

Topics: User Forum
Aug 13, 2013 at 11:05 PM

I'm developing a 2D game engine (engine + editor) and I'm trying to incorporate farseer as the default physics engine.

I have some problems on the editor because my game scenes use object hierarchy and I want to when I move a parent object (that contains a body) in the editor their children (that contains bodies) move too (like a relative position).

I've tried to use joints but I don't think they will work because I'm using World.Step(0) (when in the editor) in order to make the bodies static on the editor and still be able to use the debug view.

Is there a way to use/view the debug view and be able to manipulate objects without having them messing around?

Aug 14, 2013 at 1:22 PM
  1. Are you sure you want to create (another) engine/editor? If you're doing this for learning purposes I'd say go ahead, but otherwise I really suggest you reconsider.
  2. Do you really need / want to have your objects so tightly coupled with a physics engine? it seems to me that physics simulation would only be required when running the demo, not when editing.
Aug 14, 2013 at 2:03 PM
Edited Aug 14, 2013 at 2:04 PM
This engine I'm working in is already a public release and you can see it at ( site | features so far ), atm it does not have a physics engine (just a basic collision system) and farseer has everything I wanted.

I've figured it out how to make them work seamlessly on the editor (with relative positions too), now I'm having some struggles on debug mode ( ref )
Aug 14, 2013 at 2:29 PM
Ok, in that case I think you realy need a timestep in your physics simulation.
You can't just position a body and expect Farseer to handle it properly without a timestep.

Perhaps, what you could do, is something like this:
  • Backup your current state
  • Mark all bodies as static (except for the one you're moving)
  • Move the body to the desired location
  • Update the world with a minimal timestep
  • Listen for collisions and decide if the placement was legal
  • If an illegal collision occured, return to the original state
Aug 14, 2013 at 2:40 PM
Edited Aug 14, 2013 at 2:48 PM
I've figured it out a way to do this by using a method mattbettcher posted on this discussion forum
Vector2 destination = path.GetPosition(time);
Vector2 positionDelta = body.Position - destination;
Vector2 velocity = (Vector2) ((positionDelta / timeStep) * strength);
body.LinearVelocity = -velocity;
Aug 14, 2013 at 3:34 PM
My idea is:

Editor Mode->
  • Use Body.Position, in the editor there is no need to test for collisions when changing the position so there is no problem.
Game Mode->
  • Use the method above when the Position of the game object is changed and when the destination is reached it won't apply the destination and will let the body go free.
What do you thing? There are probably better solutions but atm I don't have much experience with farseer