I have a game that has many enemies, implemented with KinematicBody2D, that move around and bump into each other.
I move them in
_physics_process() like this:
var tree = get_tree()
tree.call_group("creeps", "move_position", delta)
This is the
move_position() function in each enemy:
var collision = _host.move_and_collide(velocity * delta)
_host.rotation = velocity.angle()
if collision and !_host.handle_collision(collision):
velocity = velocity.slide(collision.normal)
I can see from the profiler the spikes happen every time I spawn a new group of enemies. There may be 100-200 enemies on the screen at the same time. I would like to be able to spawn up to 500 enemies.
The game and controls get really laggy.
Does Frame Time 1000% mean it's taking 10 times as long to process a frame than it's supposed to?
I can also see that the
move_positionfunction is taking a lot of time.
So how can I fix this?
Is KinematicBody2D fundamentally too heavy? Is it practical to implement with Area2D? Would that even help?
Or maybe my enemy node structure is too complex?
I know there are lots of games with many enemies in them so I know it can be done, but not sure if I'm doing this the proper way. Any help appreciated.