how do i calculate the distance?

0 favourites
  • 6 posts
  • Hi!

    I have 2 sprites on my game. One is the player and the other is a sidekick that follows him (not player controlled).

    How do I make the sidekick follow the player?

    i want it to stay still unless the player gets far enough, then the sidekick walks to lessen the distance.

    I think I need an expression triger like this:

    "when the x distance between sideckick and player is bigger than X"

    could you help me? thanks.

  • System: Compare two values

    First value : distance (player.x,player.y,sidekick.x,sidekick.y)

    greater than

    second value: X

  • great!! thanks.

    Is there a way to differentiate sides? like saying: "when sidekick is at the player's right side"

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • is sidekick to the right of player = sidekick.Y > player.Y

  • Same compare :

    First value : sidekick.x

    greater than

    second value: player.x

    logic runs when sidekick is on right side of player.

    First value : sidekick.x

    < less than

    second value: player.x

    logic runs when sidekick is on left side of player.

    You can work this into sidekick variables or states perhaps i.e.

    First value : sidekick.x

    greater than

    second value: player.x

    Sidekick.playerside = "right"

    and work from there.

  • that's very good,

    thanks a lot!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)