How do I calculate the total distance traveled walking around environments?
I need to calculate the total distance my pawn moves around an environment, not just from point A to point B. I want to constantly subtract a variable as my pawn moves a certain distance going forward / backwards / left / right. Is there a way to keep updating location and track this?
Any help/direction is appreciated, Thanks!
asked Nov 19 '14 at 07:22 AM in Blueprint Scripting
I would put it where you're setting/updating the position of the player's pawn.
At some point in some blueprint you're calling something like "Add To World Location" or similar. When doing that, calculate the length of the vector you're adding to the current position and decrement your global distance counter by that length.
The formula for the length would be sqrt( x^2 + y^2 ) when only using X and Y movement for calculating the traveled distance, it gets a bit more complex when actually taking X, Y and Z movement differences into account.
answered Nov 19 '14 at 09:29 AM
Get the velocity at every frame and then calculate the distance traveled with velocity/speed * time. Velocity/Speed should be easily accessible in the player's movement component.
edit: I meant velocity and/or speed * time, not velocity divided by speed times time.
edit 2: APawn::GetVelocity().Size() * DeltaSeconds is what you want in your Tick function.
Follow this question
Once you sign in you will be able to subscribe for any updates here