Measure distance moved?

0 favourites
  • 2 posts
From the Asset Store
This is a code so you can see the same skin on all screens (peers). Each peer gets a skin, in addition to 4 directions t
  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

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