playMaker

Author Topic: Performance question  (Read 1993 times)

markadet

  • Playmaker Newbie
  • *
  • Posts: 20
    • View Profile
Performance question
« on: April 28, 2016, 05:20:17 PM »
Hello!

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!
« Last Edit: April 28, 2016, 05:23:55 PM by markadet »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15459
  • Official Playmaker Support
    • View Profile
Re: Performance question
« Reply #1 on: April 29, 2016, 05:41:04 AM »
Hi,

 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).

Bye,

 Jean

markadet

  • Playmaker Newbie
  • *
  • Posts: 20
    • View Profile
Re: Performance question
« Reply #2 on: April 29, 2016, 08:55:23 AM »
Thank you very much!  :)

I'll try to do as you say.