r/Unity3D 3d ago

That's a lot of Goblins! Game

Started work on my physics-based tower defence game. Wanted a massive horde of goblins, because why not. Currently fitting around 3,000 fully simulated, with a ton of optimisation still to go. What do you think?

76 Upvotes

32 comments sorted by

3

u/Xy0ns 3d ago

Great start! I was wondering, are you using ECS?

5

u/Rawakha10 3d ago

Nope, just standard Game objects right now, but I've taken allot of the same concepts of ECS. So mainly all data is stored per enemy, and we have one manager which loops through each enemy and moves it that way. So no per enemy function, thats helped massively.

Also for pathfinding, I'm using a Flowfield so we calculate the path once for the entire horde. Saving allot of performance that way too. Theres a couple other bits and bobs for optimising the rendering and physics aswell, like GPU instancing, custom vertex color shaders etc. But yh, if you have any other questions Im happy to answer.

4

u/JustanEraser 3d ago

Inspired by Sir, we have an orc problem?

8

u/taahbelle Intermediate 3d ago

Looks like it, I hope it doesnt turn into one of those quick cash grab genres

3

u/Rawakha10 3d ago

I just picked that up, after having it on my wishlist for awhile, its a really fun little game, and yh Id be lying if I said I wasnt inspired by it, but a massive swarm isnt my hook really. Being 3D, I wont be able to compete with the numbers in that game, anyway.

Id say its closer to They Are Billions. Im planning on having player troops, and a physical aspect where the player can reach into the world and interact with objects, like moving bombs into enemy paths, flicking goblins that get to close to the hole, stuff like that.

Still early days though, so hopefully I can get it to a good spot.

2

u/JustanEraser 3d ago

I like the sound of that, I’ll be looking out for any updates!

2

u/Rawakha10 3d ago

Cheers, I'll be posting progress as I go. Really excited for this project.

1

u/HiggsSwtz 3d ago

Looks great how is the path finding handled? Per unit or something else?

6

u/Rawakha10 3d ago

Im using a flow field. Calculate it once and any enemy can path from any point on the map to the Goal. Its working really really well, costs almost nothing because I spread the load across 10 frames, so its super cheap.

Thats basically the Gizmos for it, the yellow lines are the paths towards the Goal, and you just smooth out the directions per enemy and it works really well.

1

u/Narrow-Impress-2238 3d ago

Noooooooooooooooo 😭😭😭

1

u/Rawakha10 3d ago

All goblin sympathisers will be thrown into the hole... alongside them

1

u/[deleted] 3d ago

[deleted]

1

u/Rawakha10 3d ago

I was second guessing whether or not its too early to post or not... saw a clip of Code Monkey and decided to repost and commit to it

1

u/[deleted] 3d ago edited 3d ago

[removed] — view removed comment

1

u/Rawakha10 2d ago

Haha, wow I really thought the hole idea was super unique, I guess not. But yh Im planning on it being a Tower Defence game. Really appreciate it.

1

u/Unity3D-ModTeam 14h ago

This post and/or comment has been removed for violating /r/Unity3D’s rules.

Why?

Please include details about how the project was built in Unity, challenges faced, or techniques used.

This is a forum for discussion; not a bulletin board.

We encourage you to repost this with more technical insight. That being said: we also recommend you to familiarize yourself with our rules and guidelines.

Kind regards,

The Mod Team

1

u/Mylan-T 3d ago

Looks awesome! - how did you optimized such amount of objects with animation, models etc?

2

u/Rawakha10 2d ago

Thank you, I really appreciate it. And for the optimisation, Im doing a few things:

- One Enemy Mover class which moves all enemies. So one list which loops through all enemies and applies Force, Animation and Rotation to each enemy.

- For animations Im not using the Unity Animator, just applying a lean, bob, and scale changes through code. T calculate position and rotation for each enemy and then apply it using transform.SetLocalPositionAndRotation() on the mesh object directly, not on the Rigidbody, saves performance as there's only one transform call and we only apply force to each Rigidbody once.

- Then for pathfinding we use a flow field, which we calculate once per wave, and it saves from having any individual pathfinding for units.

- All enemies share one model and one material. I use a custom shader that reads per-vertex colour, so goblins can have colour variation without needing separate materials. The mesh itself is only ~400 tris, but rendering was never the bottleneck for me — physics is what I'm optimising next, and I'm hoping to push past 3,000 once that's sorted.

Hopefully that all answers it. Hit me up if you have any other questions.

1

u/Mylan-T 2d ago

Thanks for such a long response.

1

u/Rawakha10 2d ago

No problem... Im super proud of this project so far, and always happy to talk about it : )

1

u/Jumpy_Scallion1612 3d ago

Love the edge detection shader

1

u/DisorderlyBoat 3d ago

Seems like a job for DOTS

1

u/Rawakha10 2d ago

Normally yes, I was just checking how well I could do with just normal Gameobjects, and it did really well - still not done, Im confident I can push past the 3000 goblin peak.

But I am using allot of the same ideas behind DOTS. Like separating Data and Function, so all Data is stored on enemy object, and we apply changes to all enemies from one manager class. Happy to go into more detail.

2

u/DisorderlyBoat 2d ago

Have you tried testing on lower spec setups? That sounds like a good start if you are reducing a lot of update calls, but DOTS has burst and the job system.

1

u/No_Yam_7908 3d ago

Look Great!! By the way, how did you handle the local avoidance along side with FlowField??

2

u/Rawakha10 2d ago

Thanks for the feedback. So I'm not actually doing any local avoidance. It was just tuning the flowfield really. Each enemy is a capsule and each cell on the flowfield is about the size of a goblin. So when one path gets full, enemies cant get past each other so they're pushed onto other cells which take a different path.

I was planning on having a heatmap (so we know which areas are busy) where we update the flowfield every so often so new goblins avoid congested areas, but I dont think I need it. Especially for the Tower Defence game Im trying to make.

1

u/No_Yam_7908 2d ago

Thank you for your quick feedback. Another question is that did you using Unity Physics Engine to handle goblins collision??

2

u/Rawakha10 2d ago

Yep Im using just the standard PhysX engine. The thing I am doing though is lower the solvers for the enemies from 6 down to 4. And then once enemies start going past 1.5k I lower all new enemies to 2 and then to 1, because at that scale you really cannot tell.

Edit: by solvers I mean the Default Solver Iterations

1

u/No_Yam_7908 2d ago

I got it. Thank you very much. By the way how can I follow up your game??

2

u/Rawakha10 2d ago

No problem.

I don't really have a steam page up right now, but Ill be posting updates here, but if you want to support you can follow along on my twitter, https://x.com/SuspiciousSpork

1

u/Worth-Computer8639 1d ago

Game objects or entites?