working with large number of bodies

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By shinolikesbugs
:warning: Old Version Published before Godot 3 was released.

Hey, I am working with in the hundreds of units (right now i made them kinematicbody2D) and i want them to move based on their movement speed which is defined based on what type they are. currently i have each unit with its own timer which goes off every 0.05 seconds to update their position. Is there a better way to handle this i will be adding to these units eventually basic AI to “attack” another unit if they are in a certain distance from them. Should i use kinematic body? think movement similar to a tower defense game.

thanks

:bust_in_silhouette: Reply From: Dr_TwiSteD

I’d recomend using the fixed_process or integrate_forces hook-methods of the node, depending on your needs.

NOTE: You’ll need to enable the fixed_process hook for your node with set_fixed_process(true) like that:

func _ready():
    # tell engine to call the _fixed_process of this node each frame
    set_fixed_process(true)

func _fixed_process(delta):
    # your update code