# Creating a Distance Counter [SOLVED WITH SYSTEM EXPRESSIONS]

For questions about using Classic.

### » Tue May 31, 2011 3:27 pm

This is something I assume to be fairly simple:

[size=150:3g9qttw2]
I would like to set up a counter on my HUD for my game that tells the player how far away, in X-coordinates, he or she is from the level-end checkpoint.[/size:3g9qttw2]

So for example, if the player is 3000 pixels away from the checkpoint, the counter will say 3000. And if the player moves 20 pixels to the left, the counter will say 2980. And if the player moves 20 to the right, it will say 3020, and so on and so on.

This particular level I'm making is going from right to left, so I don't know if that would change anything.

The way I've tried to go about this is giving the checkpoint a variable "Distance", and setting it to Checkpoint.X - Player.X , and setting the HUD Text to that, but that only gives a static number, which confused me.

I have a feeling that it has something to do with the System action Compare Values, but I am pretty unversed in actions regarding those.
Check out my VGM on my soundcloud page!
Video-Game Music: E.C.2151
B
7
S
2
G
2
Posts: 193
Reputation: 1,561

### » Tue May 31, 2011 5:38 pm

Well you could use system expression "Distance between points"
Even though it's not X then only but shouldnt matter for platformer game that much or?

http://dl.dropbox.com/u/904641/distance.PNG
B
11
S
3
G
4
Posts: 622
Reputation: 3,186

### » Tue May 31, 2011 5:41 pm

Set your hud counter text to round(distance(player.x, player.y, goal.x, player.y))

Assuming you only want to measure straight along the X axis and not a vector along XY.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

### » Tue May 31, 2011 6:04 pm

Ah, thank you, that is exactly what I was looking for!

Both methods work just dandy- after that it's a matter of preference, I suppose.

Thank you both for the help. System expressions are some of the things i know least about in Construct, and more often than not, they contain the answers to my problems.
Check out my VGM on my soundcloud page!
Video-Game Music: E.C.2151
B
7
S
2
G
2
Posts: 193
Reputation: 1,561

Return to Help & Support using Construct Classic

### Who is online

Users browsing this forum: No registered users and 4 guests