anyone workout quick way to calc actor distance

TwistedMechTwistedMech Member Posts: 408
edited November -1 in Working with GS (Mac)
If my scene has several actors and I want to know which one is closest to the main game character so that the main character auto follows the closest actor, anyone work out an easy way to do this?

Comments

  • BeyondtheTechBeyondtheTech Member Posts: 809
    I only Constrain the main game character Actor's position to global Attributes, then perform any tests inside the enemy Actor. In your case, you should add another global Attribute(s) that will "instruct" the main game character will know who to follow.
  • VmlwebVmlweb Member Posts: 427
    You need to use pythagorus theorem (one of the only things I learnt in maths class)
    http://z.about.com/d/math/1/5/e/D/pythagoreantheorem.gif

    You need the co-ordinates of the two objects

    object1x
    object1y
    object2x
    object2y

    I believe this is the formula for distance between the two objects

    sqrt ( ( ( object2y - object1y ) * ( object2y - object1y ) ) + ( ( object2x - object1x ) * ( object2x - object1x ) ) )

    Hope this helps
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    @vmlweb you can do that with magnitude

    magnitude(object2x-object1x,object2y-object1y)
  • VmlwebVmlweb Member Posts: 427
    oh lol didn't know that's what that does
    thanks for the info
  • TwistedMechTwistedMech Member Posts: 408
    I tried all sorts of methods and did have 15 game.alienx/alieny vars. Having 15 * if rules for "if alien1-x < alien2-x" etc and then have this in a timer... Let's just say not so good. When level started I had all aliens try and grab one each of 15 slots.

    We could do with an array rule or some way to read each actor property in the scene so we can apply a magnitude calc or have some kind of method to list actors near to a chosen actor. :-(
Sign In or Register to comment.