I'm making 2D isometric game.
I've got like 200 instances of unit, which is kinematicBody. When nothing is happening physics process is running 200 times.
When I take like 50 units and move everything seems to be ok, fps drops little but movement looks smooth. Later I noticed that even when movement looks smooth, _physics_process
keeps jumping between 200 and 400 calls.
When I take like 100+ units and move, fps drops heavily (like 1 fps) and profiler shows _physics_process
1600 times.
I 've found out that main problem seems to be move_and_slide
(I've stripped all other functions)
Why is this happening?
EDIT:
move_and_slide
is not the issue, _physics_process
without it behaves almost the same.
My movement starts with click on navigation polygon, which returns simple navigation path, then simplified process looks like this:
func _physics_process(delta):
if state.navigationPath != null:
if state.navigationPath.size() != 0:
state.movementTarget = state.navigationPath[0]
state.movementVelocity = global_position.direction_to(state.movementTarget) * properties.movementSpeed * delta
if global_position.distance_to(state.movementTarget) > 5:
global_position += state.movementVelocity
else:
state.navigationPath.remove(0)
if state.navigationPath.size()==0:
emit_signal("statusChanged","idle")