x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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!

Product Version: Not Selected
Tags:
more ▼

asked Nov 19 '14 at 07:22 AM in Blueprint Scripting

avatar image

Zenoflare
16 1 3 6

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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.

more ▼

answered Nov 19 '14 at 09:29 AM

avatar image

Hellcat
96 3 2 7

avatar image XphyronTv May 05 '15 at 03:41 PM

i get the way you are trying to calculate the distance but sqrt(x^2+y^2) will give the displacement vector from the origin but i want the actual distance travlled as i have made a endless runner game wich can turn 90 degrees so this method wont work in that if you know anyother way pls tell me

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

more ▼

answered May 05 '15 at 03:42 PM

avatar image

mrooney
703 40 32 123

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question