Tower Defense Game! [DEVLOG]

TOWER DEFENCE GAME!

I’m remaking a tower defence game that I stopped working on, I’m remaking it because…

  1. It was hard to add custom content
  2. I learnt a lot doing it, and i can do better!
  3. Why not :wink:

I haven’t decided a name for it, so for now ill call it “happy td” or something…

8 Likes

Looking forward to this devlog!

3 Likes

When making a game the first time you learn from it, so you make it better and I see you doing that. And I am so proud of you.

2 Likes

OKAY, HERES AN UPDATE!

So i ended up remaking it again due to 3 issues:

  1. It was not as optimised as it could be.
  2. Scope creep.
  3. It’s no longer a solo project!

TLDR; I’m remaking it so its more optimised

But for you more interested people, here’s an in depth explanation on how i made the game :smile:

ENEMY MODELS
After a while, i decided to remove Humanoids from the enemy rig. This was to add custom meshes, add more flexibility and remove the overhead that I didn’t need in an enemy rig.
testmob - TEST MOB
This is the enemy i used to test, and it doesn’t use Humanoids. To animate it I instead used AnimationController with an Animator object inside it. This produces the same rig, just with less useless bloat that comes with Humanoid.

I advice anyone trying to make a polished td game to do this approach, as it also lets you turn CanCollide off and you don’t have to rely on MoveTo for waypoint movement.

MOVEMENT
Since I had removed humanoids, using MoveTo to move the humanoid to each waypoint was out of the question. There are two ways to move enemies ( as far as i know) without MoveTo.

  • CFrame
  • AlignPosition + AlignOrientation

CFrame was the one i tried first, with this modulescript:


this is a summarised version
diagram of cframe
To summarise this script, it determines the vector diffrence between the 2 waypoints.

The diagram above shows it. If a mob is moving 0.1 stud per frame (speed) over a distance of 2 studs then it will go 0.1, 0.2, 0.3, 0.4 ect… Until it reaches frame 20.

This works, but… Its overcomplicated (ish) and clunky. The server would have to update each mobs position every frame in a loop, and that isn’t good for optimisation. Especially with hordes of mobs. Another thing is that it just isn’t smooth, and doesn’t look nice.

Although it works its not a good idea… So let’s try AlignPositon + AlignOrientation!

AlignPosition has 4 properties we are interested in:
alignpos

  • MaxVelocity
  • Responsiveness
  • Mode
  • Attachment0

Firstly, we set mode to OneAttachment to be able to configure the AlignPosition easily!
image
Now, we can crack on. Assuming it’s R6, firstly we set the Attachment1 to the “RootAttachment” in your enemy model.alignpos
And instead of setting Attachment1 to something, we set its Position to the position of the target waypoint
alignpos
This will smoothly move the rig from where it is, to the position set (move it to the waypoint) which is EXACTLY what we want!

PS: This only works if the entire model is unanchored.

I used this script which I will break down to make the enemy function thats pretty long…


Okay so that might seem jarring, but the core concept is this.
Every frame, a distance is calculated from the mob to the next waypoint it needs to go to.

If it’s distance is less than 1, therefore its at the waypoint and needs to start trying to go to the next one. So it updates the AlignPosition.Position to the position of the next waypoint.

And the cycle repeats!

So we are more or less done, and you have yourself a mob that goes from waypoint to waypoint.
You can then add a check if its at the last waypoint, then damage the base health, and if it’s health is 0, delete it

This is less intensive on the server, as the movement is a Roblox Physics process.
However, It’s not perfect. If there are alot of parts, it will inherently lag on the server. And there is nothing we can do about this.
The more parts, the laggier. Unless…

CLIENT SIDE RENDERING
I’m not exactly an expert on this, but here is a brief rundown.
If parts on the server lag, then just… don’t have parts on the server?

We can use a remote event to the client to make one so that the CLIENT creates the mob model themselves.
And all the server has to do is just update values.
Which is way easier than moving EVERY SINGLE PART in a model with a physics process.

I’ll go more in-depth in a subsequent post, but this is what the remake will use as it is wayyyy more optimised.

I hope you learnt something from this, bye!

3 Likes