A Farseer Physics Gotcha

posted in Not dead...
Published November 29, 2008
Advertisement
So, I've got an idea for a game kicking around in my head and I've been building a proto-type today in order to test out the idea.

Part of this requires some 2D Physics, for which I've opted for Farseer as it's a perfect fit with C#, and on the whole it's been pretty easy to work with even for someone like myself who is a complete newbie to this sort of thing [grin]

Something which did trip me up for a bit however was bullets. You see I was creating a pool of bullets to use and then when fire was pushed (thank you SlimDX and XInput) a bullet was shot out into the world from the current location.

All well and good, however sometimes a bullet would get 'stuck' to the player, being drawn but not being updated by the physics system. This puzzled me and after checking my code was correct I took a look inside Farseer to see what was going on.

At which point the gotcha became clear;
Farseer queues up add/removes from the simulation until the next frame and it applies them by first dealing with 'add' then with 'remove'. This is where my code had a slight disagreement with it as I was removing objects and then readding them in the same frame. So, Farseer would add the object and then remove it right away.

My main issue here was I didn't realise the operations were cached until later, so a little reworking of my main loop later to defer returning objects to the pool by a frame and it all works fine.

On with the playing about then...
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement

Latest Entries

Advertisement