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"

AnswerHub Maintenance

Background maintenance is scheduled to occur between 9 - 11am EDT on Tuesday, May 21. Site operation may be slower than normal during this time and a brief interruption in operation may be observed

[Closed] Need a way to record distance traveled.

I am trying to find a way to record the distance my player controlled character has traveled. I need this for some various functionalities in my project. I looking for something like a total distance travelled that is recorded anytime the character is not idle. I am not sure how to change the world position of the character to a linear distance traveled. Any help with this is greatly appreciated.

Product Version: Not Selected
Tags:
more ▼

asked Jan 14 '15 at 02:38 AM in Blueprint Scripting

avatar image

Enabazle
15 4 5 5

(comments are locked)
10|2000 characters needed characters left

The question has been closed Mar 30 '15 at 03:12 AM by mindfane for the following reason:

The question is answered, right answer was accepted


2 answers: sort voted first

Use a function in combination with a looped "set timer" node. Set timer node runs the function you specify with a frequency you choose (e.g. every 3 seconds). You can call it after the begin play event. Just create a custom event called "Add Distance" and follow the example I attach:

Example

blueprint.png (236.2 kB)
more ▼

answered Mar 28 '15 at 09:43 AM

avatar image

alperenakyuz
2k 62 24 110

avatar image Lowpology825 Mar 28 '15 at 09:44 PM

Thanks so much for adding the image of the blueprint! Now the set of text above makes perfect sense once I'm able to see it visually represented! I will add this to my level later tonight and comment back when I get it working!

Thanks again!

avatar image Lowpology825 Mar 29 '15 at 07:26 PM

This worked perfectly! Thanks again for adding the picture!

Sorry to bother you with another question but I couldn't find a solution for this either. I have the distance working now and it is being called on screen by my UMG widget. However, it's adding very large number increments rather than constantly adding one. I'm looking to do something like kind of in this tutorial video here: https://youtu.be/VJOMdHzp3b8?list=PLZlv_N0_O1gbY4FN8pZuEPVC9PzQThNn1&t=255

Thanks!

avatar image mindfane Mar 30 '15 at 03:11 AM

Please start a new thread for a new question. Locking this thread as the solution to the original question has already been accepted.

PS: If you want to increment the distance at a constant rate, the best place to do that would be in the widget's tick or if you are using normal HUD, then within its Draw event. Instead of displaying the current value of total distance travelled, interpolate between the currently displayed value and the present value of TotalDistance travelled and display the result.

avatar image Lowpology825 Mar 30 '15 at 04:19 AM

Apologies! Will start a new thread if I have any other issues! Thanks again!

(comments are locked)
10|2000 characters needed characters left

One solution is to calculate cumulative difference between your last location and current location.

ie create a variable in your Player BP named 'LastLocation' (Vector) and another varibale 'TotalDistanceTravelled' (float). Now within your tick event, you should do this:

TotalDistanceTravelled = TotalDistanceTravelled + Length(GetLocation() - LastLocation)

LastLocation = GetLocation()

And within your BeginPlay event, do:

LastLocation = GetLocation()

TotalDistanceTravelled = 0

Hope this helps.

more ▼

answered Jan 14 '15 at 03:08 AM

avatar image

mindfane
3.4k 154 51 271

avatar image Enabazle Jan 14 '15 at 10:22 PM

Thanks, this is exactly what I was looking for. I appreciate the help.

avatar image mindfane Jan 15 '15 at 02:48 AM

If the issue is solved, dont forget to mark this thread as solved. Thanks

avatar image drUniversalis Feb 19 '15 at 06:19 PM

also keep in mind to not do it every tick...unless you are traveling zick zack at the speed of light its not nessessary to track movement xx times a second. Instead better use delta time (comes with event tick) to count up to one or a few seconds and then execute the answer above.

avatar image Lowpology825 Mar 26 '15 at 11:18 PM

I'm looking to do the same thing but being still roughly new with blueprint I don't exactly know how to go about translating what you have above into a working blueprint.

Adding the LastLocation and TotalDistanceTraveled variable, no problem. Could you possibly explain the setup a little more or maybe include a screenshot of this setup in blueprint?

Thanks!

avatar image mindfane Mar 27 '15 at 03:34 AM

Dont have my PC nearby, but i will try and post a pic as soon as possible (might take 24 hours)

avatar image Lowpology825 Mar 28 '15 at 06:23 AM

Thank you very much, I appreciate it!

(comments are locked)
10|2000 characters needed characters left

Follow this question

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

Answers to this question