Distance Traveled and 8-Direction

0 favourites
  • 5 posts
From the Asset Store
Rotate & Animation for 16 Direction & Mouse Direction
  • I'd like to calculate the distance the player has traveled over the course of the game for a stat. The hero is controlled with the 8 direction behavior. How can I track the distance traveled if I know his speed every tick from 8 direction?

    (Sorry, this is a "I'm in the 7th day of the game jam and I'm having trouble thinking about math properly" question.)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • hmm.It seems that there is nothing for that right now.

    What kind of game are you trying to make?

    We may find an easier way if you tell

  • It's not that hard. I think. On top of my head:

    Lets say your character moves with wasd keys. First you could setup a series of condition that detect these input.

    Have the player object have lastx and last y instance variables.

    Add a global variable named totaldistance.

    Then, under every (direction input) condition call

    totaldistance = totaldistance + distance(player.lastx, player.lasty,player.x,player.Y)

    player.lastx = player.x

    player.lasty = player.y

    this means, every time you press w, a, s, d, system will check the distance of lastx, lasty position, add to totaldistance, and set new lastx and lasty positions. I hope I could explain it.

  • That seems right. Wertle,can you try that to see if it works?

  • Windwalker Actually i was thinking of something much simpler, which of course came to me after a good night's sleep after the jam was over

    DistanceTraveled += Hero.8Direction.Speed*dt

    It wasn't a critical stat or anything so no big deal, it was just driving me crazy that I couldn't think of it!

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