how do i calculate the distance?

Get help using Construct 2

Post » Fri Mar 07, 2014 9:04 pm

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.
B
5
S
1
Posts: 92
Reputation: 609

Post » Fri Mar 07, 2014 9:11 pm

System: Compare two values

First value : distance (player.x,player.y,sidekick.x,sidekick.y)
> greater than
second value: X
B
47
S
18
G
84
Posts: 2,266
Reputation: 49,786

Post » Fri Mar 07, 2014 9:35 pm

great!! thanks.

Is there a way to differentiate sides? like saying: "when sidekick is at the player's right side"
B
5
S
1
Posts: 92
Reputation: 609

Post » Fri Mar 07, 2014 9:44 pm

is sidekick to the right of player = sidekick.Y > player.Y
B
18
S
4
G
1
Posts: 332
Reputation: 3,149

Post » Fri Mar 07, 2014 9:49 pm

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.
B
47
S
18
G
84
Posts: 2,266
Reputation: 49,786

Post » Fri Mar 07, 2014 10:27 pm

that's very good,
thanks a lot!
B
5
S
1
Posts: 92
Reputation: 609


Return to How do I....?

Who is online

Users browsing this forum: AlexiarTW, blackhornet and 7 guests