Creating a Custom Collision System

Hello, I am trying to make a TD game where unlike most other TD games found on Roblox, tower’s ranges are different shapes, not a complete circle around the tower

This presents an issue where I can’t just use .Magnitude to see if a tower is able to attack an enemy but have to see if the enemy is in the part

In my game, enemies are stored in a table on a server script and that table is sent to the client to render the models client side, this is in order to keep the bandwidth usage as low as possible
(The tower’s range part is on the server btw)

So how would I be able to detect if an enemy is in the tower’s range despite there being no part on the server side that represents the enemy

You can achieve it by using math, but the more complex shape of tower range, the harder math is needed.

For example your tower can attack in square range. In this case you probably should do something like this:
image

But keep in mind that using really complex shapes increases calculations weight really hard, which may influence your game optimization in a bad way.

So the more complex the shape the higher the CPU usage will be on the Server Side?
If so how can I view the Server CPU usage whilst the game is running

Just imagine: Using .Magnitude 1 time and using tons of math.sin, math.cos to calculate really small pieces of your shape. Of course server won’t like it.

Yes, when there are not really much enemies it wont have really big influence, but in case if you spawn ~250 enemies and ~250 towers then you probably will face problems like high ping, etc.

To debug your code you can use a couple of official APIs:

The first one is extremely usefull when you want to check how much time in seconds your code takes to execute:

local t = os.clock()
-- do some code here
print(`Code take {os.clock() - t} seconds to execute!`)

I’ll start testing it with a higher enemy count now
Thanks!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.