Jump to content
  • Advertisement
Sign in to follow this  
WilkinzMicawber

Help with Farseer Physics Engine Slowdown

This topic is 894 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have programmed an in-game enemy that shoots 80 small spheres in every direction away from itself, in a circle. I have to spawn the spheres away from the enemy's body enough so that they don't spawn on top of it, otherwise there is tremendous slowdown for a split second. The enemy's body type is "sensor" and its shape is a small circle.

 

The problem I'm having now is that, if two of these AIs happen to be next to each other, one spawns its projectiles partially on top of the other, so that there is tremendous slowdown. If the two AIs are far enough away from each other so that the spawning projectiles don't overlap, the slowdown doesn't happen. 

 

Is there any way to rectify slowdown when spawning objects on top of other objects? I can't seem to figure out a workaround.

Edited by WilkinzMicawber

Share this post


Link to post
Share on other sites
Advertisement

Not familiar with Farseer directly, but most physics engines allow you to specify collision flags/ masks on the objects to determine what they would collide with. It sounds in this case as if you don't want enemy bullets to hit other enemies (or the enemy that creates them). You should be able to setup a collision mask for this so that these collisions are discarded very quickly and don't go through the whole detection routine and cause your slowdown.

Share this post


Link to post
Share on other sites

..adding to what xexuxjy said, and I"m also not familiar with Farseer, but the slow down you are experience could also be related to the engine having to create these rigid bodies as well as all internal data structures used by the engine to simulate them. If the engine allow for sharing rigid body collision shapes, I would recommend using those instead ( since you mentioned that you are just spawning a bunch of small spheres). Its easier to just create 1 single rigid body collision shape vs 80, at least with PhysX it does give a slight performance boost as well as memory savings.

Share this post


Link to post
Share on other sites

Another option might be to disable the collision physics for the first few frames of the bullets life to given them a chance to not all be on top of eachother which is a worst case scenario for phyisics. Do look into the collision masking though as that could well be the fix you need and should be very easy to turn on.

Share this post


Link to post
Share on other sites

It's been a while since I used Farseer, but I remember getting a huge speed up when using the World constructor that takes an AABB - I guess that makes it use spatial hashing or something? Anyway, I tried it on a whim and got a big perf boost in my scenario - so you might want to try that if it makes sense in your scenario.

Share this post


Link to post
Share on other sites

Setting the collision masks worked beautifully. Wow, such a major difference. I was using the OnCollision eventhandler to prevent collisions before, but the mask method is so much more efficient. Thank you for all your help!

Edited by WilkinzMicawber

Share this post


Link to post
Share on other sites

The handler could still be useful for fine-grained behaviour or unusual circumstances, but yes, culling pairs early makes a huge difference :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!