Have actors in the same group follow the closest actor in the same group?

kobebeef415

  • Posts: 11
Hi I've been trying to figure this out but everything i do freezes my game . Help.

Luyren

  • *
  • Posts: 2645
Code: [Select]
Set Number to 999999
For each actor of group [your group]
-Set distance to square root of (X Center of Self - X Center of Actor of Group)² + (Y Center of Self - Y Center of Actor of Group)²
-If Distance < Number
--Set Number to Distance
--Set Closest Actor to [Actor of Group]
That's the general idea. At the end of the loop, you will have the closest actor of the specified group. Place that in a custom event and call it as needed. You should also add an if statement in your own code checking of Closest Actor has value and is alive.
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.
Twitter

kobebeef415

  • Posts: 11
it won't work. I dont know if it's because I'm doing it in a behavior other than the scene. I need it in behavior because I want to assign it to multiple actors in the group

Luyren

  • *
  • Posts: 2645
Saying "won't work" doesn't help at all. Post a screenshot of your attempt and explain more in-depth what you want to achieve.
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.
Twitter

Max Marin

  • Posts: 99
Try this, it's super good  8)
I'm human