Measuring the distance travelled by an actor in any direction?

I have a top down rpg game, and the player is free to move anywhere they please in any direction. Is it possible to track their distance moved to have a rolling total of how many miles they have travelled? Not just the distance between their start and end points, the total, actual distance moved.

Thanks!

Best Answer

  • hotMagichotMagic Posts: 266
    Accepted Answer
    make a variable for:
    total distance
    distance on a specific input move
    start of input move position
    end of input move position

    every time they press whatever input makes the character move, record x,y. When they stop that, record x,y

    calculate the distance between those. add it to the total.

    This works best of you have a movement method like if the character can only move UDRL, like in adventures of lolo. Or if you do a method in which you click on a spot to move the guy.

    with for example, a joystick input, it wouldnt work because you can do loops in a single input. That would require a more involved solution

Answers

  • iCreationZiCreationZ Member Posts: 158


    with for example, a joystick input, it wouldnt work because you can do loops in a single input. That would require a more involved solution
    This is exactly my problem. The character can move in circles, as the left and right buttons rotate them, so they can literally move any where!

    I had one idea, but I couldn't employ it because my head hurt trying to work out the logistics of it.
    :-?

    I have the players speed, so surely we could use the good old: SPEED X TIME = DISTANCE equation.

    If I had 4 variables,
    Player X 1
    Player Y 1
    Player X 2
    Player Y 2

    Timer, every 2 seconds:
    --> Change Player X 1, and Player Y 1 to self.position.X & Y
    --> timer, after 2 seconds:
    -----------> Change Player X2 and Player Y 2 to self.position.X & Y.


    I think I can somehow use a method like this to find it out...
    But now my head hurts! :D
Sign In or Register to comment.