Tower Behavior (PvZ like game)

I want to make a PvZ like game and my problem is I can’t make every tower unique to each other. Here’s what I meant.

The first event is the placement of the tower.

This conditions is to track where the cursor is and when the space were pressed the tower will be created as well as the tower range. It works perfectly.

This is the problem.

This shows the tower shoots object when the tower range was in collision on the enemy as well as when the timer is 2 sec. or higher. There is no problem at the shooting mechanics.

The problem is that I can’t link the tower and the tower range. I try to use link objects and take into account linked objects but it’s not working properly. All I want is to have a Peashooter like tower but the twist is that it has a range before it attacks. Hope someone can help me with this. If you have other method to do that, please post it here. I really need this to work.

What I would do is have an object variable “timer” on skeleton and add for every object skeleton do timer = +TimeDelta()

Also for range instead of making an object I would count the distance.

So, you can have the condition for every skeleton if timer > 2 and distance < 400 (example) shoot and do = 0 to timer…

I can cook up something quick to demonstrate it if you like, since it would be easier than to explain it here…

You need to show us the events if you want us to fix them :slight_smile:
Another option would be to use “pick the range_1 object closest to skeleton object”.
Yet another option would be to use a custom behavior.

I try to use what @MeX1Co said

I use distance to set up range. I also use x position of skeleton must be in right side to make sure that it only shoots when the enemy is on its right side. I also use x position to make sure it only attacks mostly when on the screen. The problem is that for example, I plant it on line 1, when there’s an enemy on line 5, it attacks as well because it meets the condition of distance and I don’t want that to happen. Just like this. (this is a sample only)
I just want to make the skeleton behave like a peashooter but with limited range like puff shroom. Also, sometimes when I plant many skeletons, the commands sometimes stop or not functioning right. So the solution to this is to create a custom behavior to make every skeleton works properly and individually. But the problem is that I don’t really know how to create a custom behavior. Hope you can help me to create a custom behavior that acts like a puff shroom that attacks with limited range.

So, like I said I cooked up something quick using assets from previous projects I had made…

Unzip this file in a folder and open it with gdevelop.

In essence what I did was to check that The timer is > 2, the distance is less than 600 and the turret is rotated towards the enemy…

Try it and tell me what you think.


The link you send to me are not working.

It works for me… But you can download it from google drive too here…

What about using a set distance raycast from the skeleton? It’ll only detect objects that it intersects, and firing it a specific length parallel to the x-axis, you’ll achieve the lane checking and distance limitation all in one.

1 Like

Can you show me how to it? I’m really sorry. I don’t have a lot of knowledge about GDevelop. I only know the basics like timers, variables, collisions, etc. It’s better if you can make it as a custom behavior so I can use it and I can get an idea on how to make custom behavior to make all objects function individually. I really want this to fix because I really want to make a PvZ like game. Hope you can help me :blush:

Here are the events that you’ll need to use:

And this is what it looks like:


Let us know if this is enough, or if you need further help.

1 Like

I use it and it works fine so far! The only issue I encounter is that the mouse location doesn’t connect to the grid I created. It’s because your grids are in different size and position than mine. Yours perfectly fit in 100 mouse round (I forgot the equation) and mine are not. I change it to 96 because my tiles are in 96 pixels but it doesn’t work well. Here is the file of my game. Hope you can fix it soon! Google Drive: Sign-in

By the way, the file that I shared are not compressed. Here is the compressed one.

Glad the example helped you… I cannot download the file since you have not made it shareable. I sent you an access permission from google drive.

I’m sorry for that. I now accept it. Let me know if you got it.

And done… In your example you had to change the formula to 96*floor(Mouse.X()/96) and the same for mouseY

Also I changed the collision mask on the floor where I removed the bottom 96, so that you dont get the orb below the floor.

Hope it helps and good luck with your project…

1 Like