Firing when in range

anglospanglo

  • Posts: 44
Hey guys, I'm trying to figure out how to make a unit fire only when within range of enemies. I've been trying to get it to work with regions that follow the actors, but this seems impossible to do with more than one actor at a time since you can only control the "last created region". Is there something obvious that I'm missing? I'd appreciate any advice that might put me on the right track

Thanks

Photon

  • Posts: 2697
Does this help?

http://community.stencyl.com/index.php/topic,27769.0.html

There's a block in there for getting distance between two actors.
Do NOT PM me your questions, because I likely will not respond. If I have replied to your question on the forum, keep using that topic. Thanks!

anglospanglo

  • Posts: 44
That could be extremely useful, although im not sure how to apply it. In my game there will be several allies and enemies on the screen at the same time, so what could the trigger be for initiating a comparison between the locations of two specific actors? Right now i developed a workaround where i have two actors for each character, one of them with a collision area that's equal to its range, and I use that to check for enemies within range.. It works, but it seems pretty clumsy and I think it will be very limiting in the future when I try to add more stuff. I'm sure there's a better way to do it =P

kynbo

  • Posts: 139
Use the distance formula to measure the distance between actor A and actor B
Check if the distance is close enough
If it is then actor A fires at actor B

anglospanglo

  • Posts: 44
There will be many "good guys" and many "bad guys", all of which will be dynamically spawning all the time, so there's no way to calculate that for all of them. I understand for a platformer or something you could just calculate the distance between your hero and the bad guys, but its not like that

kynbo

  • Posts: 139
Just calculate the distance between the "good guys" and the "bad guys" then pick the closest target for the "good guys"
If the closet target for the "good guy" is in range then fire.

Attributes:
Closest Target: use to store the closest target determined by the distance formula [actor]
Rate of Fire: delay the firing to make sure that bullets wont be fire every frame [number]
Rate of Fire counter: a counter that increases every frame until it reaches Rate of Fire then will be set to 0 [number]
Distance of Target: store the distance of the closest target [number]
Range of Fire: range of fire [number]
Bullet speed: speed of the bullets [number]
Group of target: group of target [actor group]
Projectile: actor type of bullet [actor type]

« Last Edit: March 15, 2014, 11:55:15 am by kynbo »

anglospanglo

  • Posts: 44
Thanks for the advice! The key step I didn't know about was that you can make an event that refers to all actors within a group. Where do you find that in the palette? I only found it by doing a search

kynbo

  • Posts: 139