Tower Defense Question

Hey guys! I have a question. I really want to start going into the Game Development. And I thought, I’m gonna start with a Tower Defense Game. They seem to be really simple and not complicated to script + I want it to be in 2D!

I’ve been watching some Tutorials on the Internet already, many good ones actually! Yet I have one Problem:
All of them are using ‘Tiles’ for placing Turrets. I really dont like that as it takes away the ‘freedom’ choice of the Player on where he wants to put the Towers.

How I want it to be? I think you know Bloons Tower Defense. I literally played BTD5 over and over again. On BTD you can place Turrets ‘everywhere’ except on the Lane where the Bloons are going their way to the ‘Death Point’.

tldr; I want the player to place their Towers wherever they want and not on setted Tiles.

I hope you can help me out! Thank you!

Hi, welcome to Game Development world.

I am happy to see you in the 2D side! :wink:

It is too easy, just use Instantiate method to create specified turret at the mouse or pointer position.

Instantiating Prefabs at Runtime

Thanks.

Still dont really see clear in this :confused:

Instantiate method is used to instantiate or clone objects or prefabs at runtime.

So, if you want to create a turret and user pointed position, you can use this method to instantiate the turret at the given position.

Also, you can use Raycasting to get the turret position on the ground.

I think you didnt really get what I want :slight_smile:

You have a Bar with your Towers. Lets take an Archer for example. He is the first Tower you can place, its the cheapest Tower etc.
Now I buy it.
NOW I want the player to decide by himself where he wants to place the Tower. He can place it everywhere except on the Path where the Enemies Spawn and follow it until they dissapear.

I’m thinking of a blockade which get placed on the Path, which prevent the player from placing Towers on it.
But I dont want any Tiles or any other Object that basicly snaps the Tower onto it. Makes Space limited, which I dont want. I hope you understand what I mean, pure English hehe

So, if you need blocking the path from being placed by the user, you need to detect the placing turret position by raycasting the turret area and determine if the below collider or object is not the path.

The simplest way to do it is to use tags on objects and add “Path” tag to path object and use Raycast to determine if the object below the placing turret does not have “Path” tag.

Doesnt sound to bad.

What about the ‘Free placing of the Towers’ tho.
Since other Tutorials want me to script a Tile or some Object that is an Area where you place a Tower.
This is exactly what I dont want. I want to a free Area, where the player can place Towers except on the blocked Path.

Yes, the raycasting is same as what you need.

It seems you don’t know what i mean by raycasting, right?

Raycasting is mostly used for detecting the object type and in this case, you can use it for detecting placeable area or blocked area.

Have a look at Physics2D.Raycast for examples.

Nono, I know what Raycasting is. A nice way for a Hide’n’Seek Game right ;D

1 Like