detect closest object

RocketBrainRocketBrain Member, PRO Posts: 269
edited November -1 in Working with GS (Mac)
i've been trying to figure this out and cant for the life of me. I need for one actor to continuously check to see which of another set of actors is closest to it. i suspect its one of the extrapolate but....the math seems to be beyond me atm.

any suggestions?

Comments

  • RocketBrainRocketBrain Member, PRO Posts: 269
    well and the pythag to calculate....its the comparing attributes to see which is less. constantly with new actors being generated.
  • old_kipperold_kipper Member Posts: 1,420
    Without any maths you could just expand a constrained round invisible actor in pulses and have the first hit object return its coordinates through game attributes then drop the invisible actor back and keep pulsing it.

    Not sure if it would be more efficient than everything constantly monitored

    Kipper
  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    Just have each object detect how far it is from main actor. Then have it update an attribute with it's value only if it is closer
  • RocketBrainRocketBrain Member, PRO Posts: 269
    jonmulcahy said:
    Then have it update an attribute with it's value only if it is closer

    yeah but detecting if its closer vs other objects that are constantly being generated/moving/destroyed

    thats whats bothering me.
  • RocketBrainRocketBrain Member, PRO Posts: 269
    whats wrong with this formula?

    sqrt((( self.TargetX - game.Gunx )^2+ (self.TargetY - game.Guny)^2)))
  • RHRH Member Posts: 1,079
    RabidWeasel said:
    whats wrong with this formula?

    sqrt((( self.TargetX - game.Gunx )^2+ (self.TargetY - game.Guny)^2)))

    There are the wrong number of brackets. This can throw a formula off completely. And if I were you I would just use magnitude, it's a lot easier.
  • RocketBrainRocketBrain Member, PRO Posts: 269
    lol hahahah totally forgot about magnitude....sigh. and yeah the paren. good eye.

    thx
Sign In or Register to comment.