How do I get bullet attribute from turret

Get help using Construct 2

Post » Mon Feb 16, 2015 2:44 pm

Hey!
I'm working on a tower defence game and having some trouble. When the turret shoot it spawns a bullet and shoot. And when bullet have traveled turret.range the bullet destroys. So far so good. But when i upgrade one turret and the range get improved the bullet dont know from wich turret it will get the range attribute. Same with damage.
B
11
S
4
G
2
Posts: 116
Reputation: 1,936

Post » Mon Feb 16, 2015 5:46 pm

you have to use instance variables for each turret so that game knows which one is higher level and then pick that
then the new bullet spawned will have longer range or dmg but that also depends on your design

https://www.scirra.com/manual/73/instance-variables
Image
B
25
S
9
G
2
Posts: 139
Reputation: 3,024

Post » Mon Feb 16, 2015 6:31 pm

Thanks @Fidasx but I dont think thats going to work. The problem is that the bullet dont know which turret has spawned the bullet.
B
11
S
4
G
2
Posts: 116
Reputation: 1,936

Post » Mon Feb 16, 2015 7:25 pm

the problem is that you need to read the link i gave you if you understand this you will have no problem

lets say we have 5 cars all the same copies of one car but each one with different stats or look (faster slower color size etc...)
and we want them to behave different to achieve that you need some instance variables for each car

speed
color
size

then you can set each car to behave or look different depending on the values of those variables

so if a turret is level 2 you have to check for a condition so the bullet coming from that turret has longer range or bigger dmg

example

compare turret instance variable "level"

turret "level"=1 bullet set bullet instance variable "dmg" to 5
turret "level"=1 turret set turret instance variable "range" to 5
turret "level"=2 turret set turret instance variable "range" to 10
turret "level"=2 bullet set bullet instance variable "dmg" to 10

this is a very simple example the way you setup events its all up to you i hope this helps you
Image
B
25
S
9
G
2
Posts: 139
Reputation: 3,024

Post » Mon Feb 16, 2015 10:43 pm

Well, thats excactly what i have done. But since the bullet dont know where it came from it just picks the variable from a turret (Dont know how it decides wich one). I guess i might have to give the bullet instance variables as well and pass those over from the turret. Thanks for the help.
B
11
S
4
G
2
Posts: 116
Reputation: 1,936

Post » Tue Feb 17, 2015 12:19 pm

If I understand you correctly, It sounds like you need to read up on picking. When you spawn a bullet from a turret, both that particular bullet instance and that particular turret are selected, so you should be able to set the instance variables for that partcular bullet, and no others. You can then destroy bullets based on whether distance traveled is greater than the Range instance var on the bullet. Perhaps if you post a capx, we can see where you are going wrong.
B
14
S
5
G
1
Posts: 189
Reputation: 1,536

Post » Tue Feb 17, 2015 6:53 pm

Thanks @bladepenguin
I think i got it now. I just dont have time to try it out. I will post a capx later if i wont get it to work.
B
11
S
4
G
2
Posts: 116
Reputation: 1,936


Return to How do I....?

Who is online

Users browsing this forum: tarek2 and 5 guests