u/Expert-Conclusion792

▲ 81 r/godot

I checked many reddit posts and some other websites, videos etc. but the things i try give even worse fps than normal physics 2d collisions most of the time.

Mob is made of characterbody2d as root,a "visual" named node2d and "Icon" as child of it, and finally a collisionshape2d.All mobs use the same script.

What i tried to compare performance / downsides:

-test_move /some mobs stop when colliding and stay there forever together

-move_and_slide / so many pushing,blocking and jittering, low performance

-move_and_collide / mobs at front blocks the mobs behind them instead of moving together

-changing the root to node2d and use global_position for movement instead of velocity / mobs overlap

-removing collisions and using areas instead to get overlapping bodies and apply a seperation force on them every frame(Spatial Partitioning?) / everyone pushing each other, jittering

-updating the physics_process less often / movement looks like low fps already

-physicsServer / i found one guide for simple bullets but my mobs will have animation and other things

-vampire survivors c++ biods and flocking video from Cakez / turned it into gdscript but it was far worse than 2d physics

-Grid-quadtree / not sure if the code was right but gave worse performance

-capping monster count / i will cap it at some point later but fps is not the only problem, smooth movement is too

Somehow it becomes O(n^2) complexity i think, for example 500 mobs=300 fps, 550 mobs= 50 fps etc.

Im using godot since 2 years but its my first time trying to optimize hundreds of mobs, i played brotato to see how it handles it(since its made with godot), somehow the mobs in brotato move together smoothly when they are near each other(no pushing, no jittering, no blocking movement, so i dont think they used move_and_slide etc), but i couldnt figure out how it happens just by looking at it. I probably did some mistakes while coding too, maybe some of the things i tried could work but didnt work properly because of unproper code.I want to mention its less likely the reason is "instantiating many scenes instead of using pool", because when i close collisions fps increases 2-3x more. In the video, i use move_and_slide and here is the code:

func _physics_process(delta: float) -> void:

if died:

	return

var direction=global_position.direction_to(player.global_position)

velocity = direction * speed 
move_and_slide()

I do really appreciate any help (Im using godot 4.6)

u/Expert-Conclusion792 — 25 days ago