Making actors move towards the nearest instance of an actor tag

BenCartBenCart Member Posts: 4
edited November -1 in Working with GS (Mac)
I can't seem to find a way for an actor to move towards the nearest instance of a particular actor tag. Any suggestions?

Comments

  • CoIinCoIin Member Posts: 197
    You could have the other actors measure their distance to the main actor, and if the distance is shorter than a game variable value, update the value to that new shorter distance, and store the location of that actor in another game variable. Then have your main actor look at the location variable to know where to head for, and also have it reset the distance variable to a high value, ready for the next frame update.
  • BenCartBenCart Member Posts: 4
    That doesn't really work as I have plan to have many instances of both. So lots of instances of Actor A chasing after the nearest instance of Actor B. Is it possible to do without having a ton of global variables and scale well?
  • quantumsheepquantumsheep Member Posts: 8,188
    @Ben

    You're talking about homing missiles, amirite? ;)

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • BenCartBenCart Member Posts: 4
    Same behaviour, different subject matter but yes, it will be basically multiple homing missiles targeting the closest of a group of multiple moving targets.
  • ORBZORBZ Member Posts: 1,304
    no easy way to do that in game salad as actors cant directly talk to each other. therefor all cross-talk has to happen in the global space...

    HOWEVER

    Given that no two actors are ever spawned or destroyed you could try this:

    In the scene space declare an actor and override the prototype. Then in that single Scene Controller instance create a VERY complex mapping between every single actor and it's "missile" counterpart. The scene controller would do the calculations and then inform the individual "missile" where to fly.

    It's messy...

    and again, this ONLY works if the total number of actors and the total number of missiles is known at design time.
  • synthesissynthesis Member Posts: 1,693
    Try using a larger invisible halo trigger disc on top of the target actor and if that touches a nearby chaser...then that chaser will chase that actor instead of the default actor. This way if the chaser's focus can always be directed to the nearest target halo/actor. Then once that target is dead...it redirects focus back to the default target...either a target actor or a target XY location on the map.
  • ORBZORBZ Member Posts: 1,304
    synthesis, but how do you tie the trigger disc to the actor as the actor moves? if you have n actors don't you need to have n discs? and if the disc moves you need n*2 global variables to track x and y position of each actor.

    your solution is good, but without the ability to bind two objects together it gets cumbersome FAST!

    I like your thinking though :)
  • BenCartBenCart Member Posts: 4
    "and again, this ONLY works if the total number of actors and the total number of missiles is known at design time."

    Unfortunately, I don't. I could constrain the number but it will be in the high double figures for the scope of the game. Looks like I have to bite the bullet and just code this (which unfortunately means the designers have to go through me to make changes). Thanks for the replies.
  • synthesissynthesis Member Posts: 1,693
    Was just giving you a nudge in a possible direction.
    Unfortunately...I don't have time to work out the details. I'm sure you can work out a clever solution in time.

    Welcome to game development! It's not that easy...but GS sure helps things!
Sign In or Register to comment.