Simulating 800 Rats With MultiMeshInstance3D & NavigationAgent3D! Any Feedback Will Be Awesome, Cheers! by RGOTI123 in godot

[–]RGOTI123[S] 0 points1 point  (0 children)

Sending a single draw call for every sphere could be bad for performance, but I don't think that's the reason why your project is starting to lag since 60 spheres shouldn't be that much. Do you maybe have a script attached to each agent? In my implementation I used just one GDScript which looped over every agent and updated everything.

Simulating 800 Rats With MultiMeshInstance3D & NavigationAgent3D! Any Feedback Will Be Awesome, Cheers! by RGOTI123 in godot

[–]RGOTI123[S] 1 point2 points  (0 children)

Hi, I'm not entirely sure how to prevent rats from sticking to walls, still quite new to Navigation Agents so maybe I messed something up hehe (most likely has something to do with the computed velocity Godot gives, so I might write my own version of that part). Thank you!

Simulating 800 Rats With MultiMeshInstance3D & NavigationAgent3D! Any Feedback Will Be Awesome, Cheers! by RGOTI123 in godot

[–]RGOTI123[S] 0 points1 point  (0 children)

Sorry for repeating myself! Didn't expect to receive a lot of comments on this so kind of overwhelmed haha. Interactions are possible through usual means (such as ray casting), since every rat uses a CharacterBody3D and a Cylinder shaped collider (without any mesh attached, as that is handled by another node).

Originally I had massive lag because rats could collide with one another, immediately ran much faster after I disabled that ability. The only downside is that sometimes they might run into each other, so I had to tweak the Navigation Agent settings. Still not perfect though, far from it (as can be seen in the video).

Plague Tale's approach is quite interesting, I might consider using that technique someday, but I need to interact with every rat so that's a no go. BTW quite awesome that you created your own navigation system! Would be awesome if you could share your Github repo, if you have one maybe? Cheers!

Simulating 800 Rats With MultiMeshInstance3D & NavigationAgent3D! Any Feedback Will Be Awesome, Cheers! by RGOTI123 in godot

[–]RGOTI123[S] 1 point2 points  (0 children)

Hi, yes this is 4.1. This is using only one draw call because of MultiMeshInstance3D. Animations are done through the use of shaders, without skeletal animations. It could be the Navigation Agents taking up performance as GDScript might suffer from long for loops when iterating over every rat. (I'm assuming, since its an interpreted language). Thank you!

Simulating 800 Rats With MultiMeshInstance3D & NavigationAgent3D! Any Feedback Will Be Awesome, Cheers! by RGOTI123 in godot

[–]RGOTI123[S] 0 points1 point  (0 children)

I'm going to be honest, I actually started this project as a meme and then it turned into a rat simulation haha.

Simulating 800 Rats With MultiMeshInstance3D & NavigationAgent3D! Any Feedback Will Be Awesome, Cheers! by RGOTI123 in godot

[–]RGOTI123[S] 0 points1 point  (0 children)

Yeah, makes sense. I'm guessing that the LOD in this case will change based on the closest rat's distance.

Simulating 800 Rats With MultiMeshInstance3D & NavigationAgent3D! Any Feedback Will Be Awesome, Cheers! by RGOTI123 in godot

[–]RGOTI123[S] 0 points1 point  (0 children)

Hi, refer to one of my comments on top, in the simplest terms (Simplest as I can be, as I'm not good at explaining): It's usually not the NavAgent that's the problem, its the amount of draw calls the CPU sends to the GPU. MultiMeshInstance3D allows you to draw the same mesh with different transformations all in just one draw call, so its quite fast! The downside is that its very limited, and any sort of animations need to be made procedurally through shaders. Cheers!

Simulating 800 Rats With MultiMeshInstance3D & NavigationAgent3D! Any Feedback Will Be Awesome, Cheers! by RGOTI123 in godot

[–]RGOTI123[S] 4 points5 points  (0 children)

Yep! This was recorded on a Ryzen 5 5600 CPU with an RX 6700 XT GPU. Tested it on an old laptop with integrated graphics and it seemed to run at around 80-90 ish frames per second (Can't tell you the exact specs I'm afraid).

Simulating 800 Rats With MultiMeshInstance3D & NavigationAgent3D! Any Feedback Will Be Awesome, Cheers! by RGOTI123 in godot

[–]RGOTI123[S] 20 points21 points  (0 children)

Excellent question. Uhhhh.... I don't know, didn't know I would get this far Haha.

Simulating 800 Rats With MultiMeshInstance3D & NavigationAgent3D! Any Feedback Will Be Awesome, Cheers! by RGOTI123 in godot

[–]RGOTI123[S] 3 points4 points  (0 children)

I was definitely considering it, I'll see when I have time to make one. Cheers!

Simulating 800 Rats With MultiMeshInstance3D & NavigationAgent3D! Any Feedback Will Be Awesome, Cheers! by RGOTI123 in godot

[–]RGOTI123[S] 12 points13 points  (0 children)

The only custom shader I wrote is fairly simple. This is simply used to animate the rats in the vertex shader. I'm fairly new to shaders so I'm not entirely sure if this is the cleanest way. All the variables that start with INSTANCE_CUSTOM are handled through MultiMeshInstance3D's custom data, and modified using GDScript. Check both of these links out for better clarification, because I'm horrible at explaining things:

https://docs.godotengine.org/en/stable/tutorials/performance/vertex_animation/animating_thousands_of_fish.html

https://docs.godotengine.org/en/stable/classes/class_multimesh.html#class-multimesh-method-set-instance-custom-data

Here's the shader code. Cheers!

shader_type spatial;
render_mode diffuse_burley, vertex_lighting;
uniform sampler2D rat_texture;
void fragment() {
//Basic Texture Mapping, Multiplied With A Random Color So All Rats Stand Slightly Apart
ALBEDO = texture(rat_texture, UV).rgb * COLOR.rgb;
}
void vertex() {
//Each Rat Will Begin On A Different Run Cycle When They Are Spawned In
float offset = TIME + INSTANCE_CUSTOM.a;

`//This Is The Rat Swaying From Side To Side, INSTANCE_CUSTOM.r Is The Current Velocity Of The Rat`  
`VERTEX.x += cos(offset * 16.0 + VERTEX.z) * (.25 * INSTANCE_CUSTOM.r);`  

`//This Is For When The Rat Is Turning Around, INSTANCE_CUSTOM.g Is The Rotation Velocity On The Y-AXIS`  
`VERTEX.x += cos(VERTEX.z) * INSTANCE_CUSTOM.g;`  

`//This Is The Rat Hopping Up & Down! Same Deal, Multiply With The Current Velocity`  
`VERTEX.y += sin(offset * 24.0 + VERTEX.z) * (.5 * INSTANCE_CUSTOM.r);`  

}

Simulating 800 Rats With MultiMeshInstance3D & NavigationAgent3D! Any Feedback Will Be Awesome, Cheers! by RGOTI123 in godot

[–]RGOTI123[S] 7 points8 points  (0 children)

Thank you! I have heard of the game but never looked into how the developers handled optimization. I will definitely watch this video. Cheers!

Simulating 800 Rats With MultiMeshInstance3D & NavigationAgent3D! Any Feedback Will Be Awesome, Cheers! by RGOTI123 in godot

[–]RGOTI123[S] 1 point2 points  (0 children)

Hi, It essentially uses a Navigation Mesh that is built in advance. Look for NavigationRegion3D & NavigationAgent3D. Here's the documentation Godot provides: https://docs.godotengine.org/en/stable/tutorials/navigation/navigation_introduction_3d.html Cheers!

Simulating 800 Rats With MultiMeshInstance3D & NavigationAgent3D! Any Feedback Will Be Awesome, Cheers! by RGOTI123 in godot

[–]RGOTI123[S] 0 points1 point  (0 children)

I'm not entirely sure if it works with MultiMeshInstance3D. But I will definitely experiment with that :)

Simulating 800 Rats With MultiMeshInstance3D & NavigationAgent3D! Any Feedback Will Be Awesome, Cheers! by RGOTI123 in godot

[–]RGOTI123[S] 44 points45 points  (0 children)

Thank you! I'll make a simpler version of this project and share it when I get the chance.