Measure distance moved?

Get help using Construct 2

Post » Tue Oct 09, 2012 7:43 pm

Hello all.
I seem to be having another distance related problem again. What I'm trying to do this time is to make it such that every time the playable character moves a certain distance (among other things) they gain a resource charge (which is depicted as a visual icon). I've been searching this forum, and I asked about distance before, but I'm not entirely sure how to apply the distance formula over time using previous instances.

Any measure of assistance would be much appreciated.
Posts: 36
Reputation: 1,274

Post » Tue Oct 09, 2012 9:04 pm

It's pretty simple, just add the distance the player has moved every tick to a variable, then check when the variable is greater than or equal to the certain distance.

To measure the distance the player has moved you need to save the player's position to some variables. Give your player sprite 3 instance variables and call them "dist", "oldx" and "oldy". Then every tick do these three things:
1. add distance(self.x, self.y, self.oldx, self.oldy) to dist
2. set oldx to self.x
3. set oldy to self.y

You will probably want to set oldx and oldy at the start of layout to the players position, otherwise the distance from (0,0) to the player will be used.
Posts: 5,517
Reputation: 83,472

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 11 guests