Distance between actors

NMansellNMansell Member Posts: 143
edited August 2012 in Working with GS (Mac)
Is there a coding way to set a distance between the actors?

Comments

  • ironDanironDan Member Posts: 148
    edited August 2012
    magnitude( game.TargetX - self.Position.X , game.TargetY - self.Position.Y )

    That expression will measure the distance between two actors, and you can create a rule to do whatever when the distance is = or > or <
  • Dell7730Dell7730 Member, PRO Posts: 388

    @ironDan said:
    magnitude( game.TargetX - self.Position.X , game.TargetY - self.Position.Y )

    That expression will measure the distance between two actors, and you can create a rule to do whatever when the distance is = or > or <

    Can you please illustrate the rule?

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    This thread is three years old so I'm not sure ironDan is going to be responding but I'll see if I can help you out.

    If you set the left side of the rule condition to "Numeric Expression" you can then type in or select the magnitude() function from the math functions drop-down menu. Be sure to select attribute names (e.g. game.TargetX) from the attribute drop-down menu instead of typing them in.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • AJaymzAJaymz Member, PRO Posts: 164
    edited March 2015

    @NMansell

    Create REAL game attributes TargetX and TargetY.

    In one of your actors:
    -CONSTRAIN TargetX to self.PositionX
    -CONSTRAIN TargetY to self.PositionY
    (Constrain if your actor will be moving otherwise just use Change)

    In other actor you can check the distance by:

    • When numeric expression Magnitude(TargetX-self.positionX, TargetY-self.PositionY) is "whatever distance" then do whatever.
  • Dell7730Dell7730 Member, PRO Posts: 388
    edited March 2015

    Here's what I need help with: This is what I have for my Daisy Chain of say 2 Actors, it works perfect , when there's no movement, all actors stay on top of each other, when there's movement by the lead Actor, the other Actor stays behind and follows. What I need help with is, How can I make it where I can set them apart but stay together at a set distance?

    Constrain self.rotation to vectorToAngle(self.motion.linearVelocity.x,self.motion.linearVelocity.y)
    Constrain self.motion.linearVelocity.X to 10*(ACTORTOFOLLOW.position.x-self.position.x)
    Constrain self.motion.linearVelocity.Y to 10*(ACTORTOFOLLOW.position.y-self.position.y)

    Thanks for all the time and help, really appreciate it.

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879

    @dellagarpo -- Give this a try.
    The -75 is the distance behind the leader. (Its negative because its behind the leader.)

  • Dell7730Dell7730 Member, PRO Posts: 388
    edited March 2015

    @RThurman said:
    dellagarpo -- Give this a try.
    The -75 is the distance behind the leader. (Its negative because its behind the leader.)

    i'm sorry, i'm so exhausted can't think straight, lol... and a little drunk too haha

    How would you rewrite this to add a distance of 100 pixels?
    Constrain self.motion.linearVelocity.Y to 10*(ACTORTOFOLLOW.position.y-self.position.y)
    Thanks!

  • BigDaveBigDave Member Posts: 2,239

    didn't knew the game.targetX trick thanks guys

    so far I constrain X of object A with a global variable and the same for object B with another global variable

    than i used abs(ObjectA_X-ObjectB_X)

    that gives me netto distance with no minus sign.
    abs= absolute

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879

    @dellagarpo said:
    i'm sorry, i'm so exhausted can't think straight, lol... and a little drunk too haha

    How would you rewrite this to add a distance of 100 pixels?
    Constrain self.motion.linearVelocity.Y to 10*(ACTORTOFOLLOW.position.y-self.position.y)

    Hmmm.... The short answer is you can't! You are trying to use the wrong equation. (That is like asking, "how can I make 25*10 equal 100?"

    The equation I supplied is the correct one. And then you can change the "-75" to "-100"

    The long answer is that you need to use some trig calculations. This is because you need to find the spot 100 pixels behind the lead actor. That spot designates the location that you want the follower actor to move to. But because the lead actor rotates, it takes a little trig to find the right x,y coordinate. (That x,y coordinate constantly changes as the lead actor rotates around.)

Sign In or Register to comment.