How do I get bullet attribute from turret

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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

  • Thanks Fidasx but I dont think thats going to work. The problem is that the bullet dont know which turret has spawned the bullet.

  • 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

  • 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.

  • 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.

  • Thanks

    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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)