A solution for spawning turrets that I find a bit more elegant is having a single slot object (clickable) which can be used for all turrets (using a ds_map for each tower's data). That slot object, once clicked and the button is hold, can draw the turret's sprite at the mouse coordinates. This way you have only one of each turret object and a slot, instead of three objects per turret.
For those of you using physics, use this in the alarm[0] event (projSpeed is substituted for 10): if (instance_exists(objectToShoot)) { var bullet = instance_create_depth(x, y, -9, oBullet);
var dir = point_direction(x, y, objectToShoot.x, objectToShoot.y);
Here's a recommendation for the circle and line things. Have them only appear when the mouse is hovering over the circle so when you're at later rounds your screen isn't full of circles and lines. Also, is there going to be stuff on upgrade? Or will we be figuring it out on our own?
I absolutely love your tutorial!!! Just finished the first two videos and looking forward to the third video! Like SB 64, I would love it if you made a tutorial on upgrading towers. I assume if you wanted to change the sprite upon upgrading it would be something like using the destroy code on the existing tower and a build code for the new one. I have a bad habit of making things my own while following tutorials, lol. So, all three of my towers already act differently. My first tower shoots the nearest, the second one shoots the furthest (but won't shoot any of the ones in range if the furthest one is not in range...can't seem to fix that), and my third tower does both simultaneously. I also have used images for my sprites and my background layer to create a Sponge Bob theme for my kids...LOL So, my enemies are Plankton, my towers are Sponge Bob, Krabs, and Squidward (playing his flute). Obviously, Squidward playing his flute will be the strongest and harms the nearest and furthest simultaneously (I wanted him to hurt all towers in range but couldn't figure that out yet). I also put in some code to prevent players from placing towers in the attack range of other towers and gave my towers each a different range. This way, towers can't be placed on each other or grouped really close so players have to use a bit more strategy. Please do consider creating more tutorials on this game type because it has been uber helpful and I can't wait to learn more!
If you're like me and did not what the circle showing but wanted to display if the player clicks on the tower?. Go into you tower3D or your TowerDrag group, have a create event that has the range stored then create a draw event ; "draw_circle(x,y,range,true)" ; now when you click on the tower it will show the range of the tower before you can place it down. Enjoy!
the "bullet.direction" doesn't seem to apply on the bullets.... 15:00 ... ooooooooooh... ".direction" is not the same thing as "image_angle"... Nevermind, Sorry! Great tuto!
Ive got tiny problem with this. I create a tower (already placed down on map for purpose of testing but when enemies aprouch the tower and enter its radious they only fire at enemies in certain direction. Like fire only in the upper part of the circle
Interesting problem, the only thing I can think of without looking at the code is to check the origin of your sprites and be sure it matches the tutorial.
Use this code if (instance_exists(objectToShoot)){ // Verifica se o temporizador de disparo está ativo if (!alarm[0]) { // Criando balas var bullet = instance_create_depth(x, y, -9, oBullet);
// Configurando a bala bullet.speed = 10; bullet.direction = point_direction(x, y, objectToShoot.x, objectToShoot.y);
// Define o temporizador de disparo para a taxa de disparo desejada alarm[0] = fire_rate; } } else { shooting = false; }
Hi! I can't seem to find my error. not literally error but I can't put towers smoothly sometimes it create one sometimes not. we have the same code. can you/someone help me?
Hey! I have a little problem with the oTower1C object. I have the exact same code as shown in the video, but whenever I click on the object in the game nothing happens. Would anyone know how to fix this? maybe it's because of the new update that this doesn't work anymore? any help would be appreciated :)
Hello I don't know if I'll get a response here because this video is online since 2017 but I have a problem that I'm currently not able to fix : I used the same code than you but my bullets aren't going on ennemies : they appears on my turrets, the line follows the ennemies but bullets aren't going on ennemies ? what can I do ?
@@RealTutsGML Hello, im getting this error, on oTower1, ___________________________________________ ############################################################################################ ERROR in action number 1 of Draw Event for object oTower1: local variable (-1610512709, -2147483648) not set before reading it. at gml_Object_oTower1_Draw_0 (line 5) - if(en != noone){ ############################################################################################ gml_Object_oTower1_Draw_0 (line 5)
Actually, is recommended that you lose coins after you place tower because if you press and then doesn't want to use, the money will be not there, pls fix that.
Uhh.. line 7 of the draw event for the towers just randomly started breaking This is the code draw_self(); if(mouseOver(x,y,sprite_width,sprite_height)) draw_circle(x,y,range,true); var en = instance_nearest(x,y,oRed) or instance_nearest(x,y,oSpd) or instance_nearest(x,y,oBig) if(en != noone){ if(point_distance(x,y,en.x,en.y)
6 years ago and it still works. nice!
A solution for spawning turrets that I find a bit more elegant is having a single slot object (clickable) which can be used for all turrets (using a ds_map for each tower's data). That slot object, once clicked and the button is hold, can draw the turret's sprite at the mouse coordinates. This way you have only one of each turret object and a slot, instead of three objects per turret.
For those of you using physics, use this in the alarm[0] event (projSpeed is substituted for 10):
if (instance_exists(objectToShoot)) {
var bullet = instance_create_depth(x, y, -9, oBullet);
var dir = point_direction(x, y, objectToShoot.x, objectToShoot.y);
bullet.phy_speed_x = lengthdir_x(projSpd, dir);
bullet.phy_speed_y = lengthdir_y(projSpd, dir);
bullet.speed = projSpd;
alarm[0] = fire_rate;
} else {
shooting = false;
}
Here's a recommendation for the circle and line things. Have them only appear when the mouse is hovering over the circle so when you're at later rounds your screen isn't full of circles and lines. Also, is there going to be stuff on upgrade? Or will we be figuring it out on our own?
Great idea, part 3 doesn't include upgrades.
@@RealTutsGML So will there be like a bonus episode for that or no? I understand if you cant but plz make an episode of that.
I absolutely love your tutorial!!! Just finished the first two videos and looking forward to the third video! Like SB 64, I would love it if you made a tutorial on upgrading towers. I assume if you wanted to change the sprite upon upgrading it would be something like using the destroy code on the existing tower and a build code for the new one.
I have a bad habit of making things my own while following tutorials, lol. So, all three of my towers already act differently. My first tower shoots the nearest, the second one shoots the furthest (but won't shoot any of the ones in range if the furthest one is not in range...can't seem to fix that), and my third tower does both simultaneously. I also have used images for my sprites and my background layer to create a Sponge Bob theme for my kids...LOL So, my enemies are Plankton, my towers are Sponge Bob, Krabs, and Squidward (playing his flute). Obviously, Squidward playing his flute will be the strongest and harms the nearest and furthest simultaneously (I wanted him to hurt all towers in range but couldn't figure that out yet).
I also put in some code to prevent players from placing towers in the attack range of other towers and gave my towers each a different range. This way, towers can't be placed on each other or grouped really close so players have to use a bit more strategy.
Please do consider creating more tutorials on this game type because it has been uber helpful and I can't wait to learn more!
If you're like me and did not what the circle showing but wanted to display if the player clicks on the tower?. Go into you tower3D or your TowerDrag group, have a create event that has the range stored then create a draw event ; "draw_circle(x,y,range,true)" ; now when you click on the tower it will show the range of the tower before you can place it down. Enjoy!
Thank you for all your Tutorials, they really helped me!
Keep it up👍🏻
Thanks! I'm really glad you're enjoying them.
I need some help, I have the code itself exactly the same as yours, yet with the firerate, it fully automatically fires a bunch of bullets at a time
when is part 3 coming out?
thx it helped me for my rts i did not know how to place the turret
my tower keeps shooting even when the enemy is out of it's range, what could it be?
the "bullet.direction" doesn't seem to apply on the bullets.... 15:00
...
ooooooooooh... ".direction" is not the same thing as "image_angle"... Nevermind, Sorry! Great tuto!
Ive got tiny problem with this. I create a tower (already placed down on map for purpose of testing but when enemies aprouch the tower and enter its radious they only fire at enemies in certain direction. Like fire only in the upper part of the circle
Interesting problem, the only thing I can think of without looking at the code is to check the origin of your sprites and be sure it matches the tutorial.
Use this code
if (instance_exists(objectToShoot)){
// Verifica se o temporizador de disparo está ativo
if (!alarm[0]) {
// Criando balas
var bullet = instance_create_depth(x, y, -9, oBullet);
// Configurando a bala
bullet.speed = 10;
bullet.direction = point_direction(x, y, objectToShoot.x, objectToShoot.y);
// Define o temporizador de disparo para a taxa de disparo desejada
alarm[0] = fire_rate;
}
} else {
shooting = false;
}
the *Left_Pressed* one it supposed to *Left_Release* and the *Left_Pressed*
just the same as the *step*
I tried this but it doesn't work! When I click the tower in the bottom corner nothing happens! Help!
same
@@Zyrex216 Same, does anyone find something about it guys ? i would love to know !
@@Zyrex216 In my case i have fail the code on the oTower1C and write coins instead of cost in the 3 line :p
now it works perfectly !
Dan Botton ok was going to say check events ans objects are in the right place
my duplicated turrets arent changing their form?? i copied everything
it will not allow me to place the towers down and they also don't shoot.
8:26 i can click on the towers but not place the tower can someone help me pleaz.
wow the differences in how the logic changes between 1.4 and 2 are mind boggolingly illogical
Hi! I can't seem to find my error. not literally error but I can't put towers smoothly sometimes it create one sometimes not. we have the same code. can you/someone help me?
i keep getting this FAILED: Run Program Complete in output box
where part 3?
Does anyone know how make tower attack at different enemies (different object)
var en = instance_nearest(x,y,oWhatever) or instance_nearest(x,y,oExample) rinse and repeat per enemy
Hey! I have a little problem with the oTower1C object. I have the exact same code as shown in the video, but whenever I click on the object in the game nothing happens. Would anyone know how to fix this? maybe it's because of the new update that this doesn't work anymore? any help would be appreciated :)
Change the Left Pressed to Left Release, and the Left Release to Left Pressed :-)
Hello I don't know if I'll get a response here because this video is online since 2017 but I have a problem that I'm currently not able to fix : I used the same code than you but my bullets aren't going on ennemies : they appears on my turrets, the line follows the ennemies but bullets aren't going on ennemies ? what can I do ?
Set the bullet speed in the create event to any number you'd like. i.e. speed = 10;
Hope that helps good luck!
@@RealTutsGML Hello ! I just rewatch and restart all the tuto and it works perfectly
@@RealTutsGML Hello, im getting this error, on oTower1,
___________________________________________
############################################################################################
ERROR in
action number 1
of Draw Event
for object oTower1:
local variable (-1610512709, -2147483648) not set before reading it.
at gml_Object_oTower1_Draw_0 (line 5) - if(en != noone){
############################################################################################
gml_Object_oTower1_Draw_0 (line 5)
your website seems to be down, just so you know
My bullets dont fly to enemy. They are creating in tower and stay here. Where was i can make misstake?
my code alarm [0] :
if(instance_exists(objectToShoot)){
var bullet = instance_create_depth(x,y,-9,obj_bullet);
bullet.speed = 10;
bullet.direction = point_direction(x,y,objectToShoot.x,objectToShoot.y);
alarm[0] = fire_rate;
}else{
shooting = false;
}
I has found my misstake. I forgot about physics. it was eneble in room
"Amwriter free" i use to mod rusted warfare and do the coding but coding is hard to remember so i have to copy a bit
Actually, is recommended that you lose coins after you place tower because if you press and then doesn't want to use, the money will be not there, pls fix that.
My towers shoot once and then they just stop... ples help
did you remember to set alarm 0 to equal fire rate in the if statement?
@RealTutsGML icant put towers can you help me?
Late reply, but drag your instance layer above the tile layer.
i dont think this code works anymore i tried and tried and couldn't get it to work.
mad man
7:36
15:25
i cant drag the tower
same, all my code is identical, not sure what's going on
I needed to swap the left click events on both the clickable and dragged,
so change Pressed Released on both oTower1C and oTower1D
@@awaite1 This helped me 4 years later so thanks!
hi
Hello
Uhh.. line 7 of the draw event for the towers just randomly started breaking
This is the code
draw_self();
if(mouseOver(x,y,sprite_width,sprite_height))
draw_circle(x,y,range,true);
var en = instance_nearest(x,y,oRed) or instance_nearest(x,y,oSpd) or instance_nearest(x,y,oBig)
if(en != noone){
if(point_distance(x,y,en.x,en.y)
3:19