Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: markadet on April 28, 2016, 05:20:17 PM

Title: Performance question
Post by: markadet on April 28, 2016, 05:20:17 PM

I'm doing a 2D platformer with quite big levels, with more than 100 enemies in the scene. A lot of these enemies have multiple boxcolliders 2D to detect the ground & various event.

I did a gif showing these colliders a few days ago, here it is, for illustration purpose :) :

To improve performance, I made a FSM on enemy object doing a Get Distance action, every frame. If the player is near, it activates the other FSM, the children detection objects, etc. Before that, the enemy object is not active. So when the level is played, 90% of the enemies a just doing GetDistance on the player object & wait to be active.

It works (still a little work to do on this), the performance have improved. But is it the good way to do? Considering this FSM will be used by nearly every object in the game, should I do another action costing less, or even use Get Distance, but not every frame?

I'd really like to hear what you think of this. Thank you!
Title: Re: Performance question
Post by: jeanfabre on April 29, 2016, 05:41:04 AM

 Get distance is VERY costly ( squareRoot math is costly), so I would refrain from using it everywhere...

Colliders and triggers will be a lot more efficient and easy to work with.

Have your player trigger the enemy which is set in a kind of sleep mode and when trigger, enable the fsm and all your functionnalities.

Your enemy should have a collider that is exactly fitting them, and only your player should a larger collider to wake up enemy and props ahead ( as well as disable them when exiting).


Title: Re: Performance question
Post by: markadet on April 29, 2016, 08:55:23 AM
Thank you very much!  :)

I'll try to do as you say.