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"

Have a total distance traveled constantly update?

Hello!

I originally followed this thread to be able to record the total distance traveled in game and have that working! However as of right now, it adds large integers rather than continuously counting by 1 like I want it to.

I received help from 'mindfane' on the forums and this was his suggestion:

"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."

Unfortunately, I just don't really know how to get running what he has suggested. Below is what I started to come up with but just can't figure out how to get the displayed TotalDistance traveled from the 'Total Distance' function from within the widget.

alt text

Product Version: Not Selected
Tags:
more ▼

asked Mar 30 '15 at 03:08 PM in Blueprint Scripting

avatar image

Lowpology825
13 2 5 6

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

1 answer: sort voted first

I'm not sure if I'm misunderstanding, but couldn't you keep track of the 'last position' since updating and add the difference between the current position and the last to the total? (eg. totalDist = (currentPosition-lastPosition).Size())

more ▼

answered Mar 30 '15 at 03:13 PM

avatar image

Grogger
797 49 62 94

avatar image Lowpology825 Mar 30 '15 at 04:30 PM

Sorry, I forgot to include the thread so you could see the original Distance Traveled blueprint in there but I have now updated it. So far the image below is what I have for calculating the Distance Traveled.

Is your suggestion meant for the widget or just for the character blueprint itself for tracking the distance? Because I am already adding the difference between the 'last position' and my current position to get the distance traveled so far.

My problem is that it adds chunks of numbers rather than adding 1 at a constant rate. For example in this video.

avatar image Grogger Mar 30 '15 at 04:44 PM

Ah, my suggestion was simply for recording the actual distance travelled.

So from my understanding, you're looking to display the distance travelled no more than 1m every constant update (ie. not every tick)? This would mean that the actual distance travelled might be out of sync with the displayed value.

If this is the case, then you can store the time elapsed and only update one it's passed it (for constant rate), and only display a single meter toward the actual distance when it does update.

Off the top of my head, it might look like this: eg. for 1 update every half second:

 DisplayedMeters = 6;
 ActualMetersTravelled = 10;
 CurrentElapsed = 0.35s;
 
 OnTick: 
 CurrentElapsed = CurrentElapsed+Delta
 if(CurrentElapsed > 0.5)
 {
 CurrentElapsed = 0;
 DisplayedMeters  = Min(ActualMetersTravelled, DisplayedMeters +1);
 }

avatar image Grogger Mar 30 '15 at 05:14 PM

An alternative to this is to use a looping timer that triggers every 0.5 seconds to update (this might be easier to read, and it doesn't require storing any values)

avatar image Lowpology825 Mar 30 '15 at 05:02 PM

Yes, as quickly as possible though probably through every constant update though if I could do every tick then I wouldn't mind that. If the displayed distance is a little behind the actual distance traveled, that shouldn't be too bad as the player wouldn't know. Unless it really effects something then it shouldn't be a problem.

Sorry but I somewhat understand the code, I just don't know how this translates into Blueprint? I'm setting it up right now to the best of my ability and this is what I have so far and I don't know if I am understanding this correctly.

alt text

avatar image Grogger Mar 30 '15 at 05:04 PM

The CurrentElapsed should be updated every frame with the delta, the "SetCurrentElapsed" should come before the branch in this case

avatar image Lowpology825 Mar 30 '15 at 05:09 PM

CurrentElapsed = 0; DisplayedMeters = Min(ActualMetersTravelled, DisplayedMeters +1); }

I don't fully understand this part or where exactly I put it? Right now the blueprint scripting I have above is in the event graph of my on screen HUD widget. I was going to place this second bit in the actual Total Distance Function I have that binds it to the on screen number.

avatar image Grogger Mar 30 '15 at 05:12 PM

So that bit of code is executed if the branch for (CurrentElapsed > 0.5) returns true.

What it is doing is resetting the timer to 0, so it can start it's countdown anew (CurrentElapsed = 0), and then updating the displayed number by +1 (the min makes sure that we don't update passed the actual meters travelled)

avatar image Grogger Mar 30 '15 at 05:19 PM

I haven't tested this, but off the top of my head using a timer might look like this:

alt text

avatar image Lowpology825 Mar 30 '15 at 05:21 PM

I'm curious as to where exactly that is in the blueprint? Should I be adding that to my Character Blueprint it would seem?

avatar image Grogger Mar 30 '15 at 05:23 PM

It could probably be anywhere that can access your HUD(maybe even in the HUD)

avatar image Lowpology825 Mar 30 '15 at 05:31 PM

Sorry, I've kind of gotten jumbled up and lost now lol. By the way thanks for keeping track of this so quickly and answering all of my questions!

  1. I have the current elapsed setup in the HUD blueprint

  2. I now have the UpdateDisplayed setup in my HUD blueprint though I've had to add a Cast to (My Character blueprint) with a Get Player Character so that the Total Distance Traveled has a target.

How do these two actually interact? As of right now I don't know how to call this so that I can update it to the HUD so it shows on screen.

By the way I replaced your ActualMetersTraveled with my Total Distance Traveled as that is connected to the blueprint in my character that is actually calculating the distance.

What I have so far: alt text

Updated: I have to have the UpdateDisplayed setup in my character as I can't access it from within the HUD unless it is in there. So it can't be in the HUD itself.

avatar image Grogger Mar 30 '15 at 05:36 PM

Oy vey I've made a mess of things haha.

The UpdateDisplayed setup REPLACES the current elapsed setup.

All you should need is the blueprint pic I showed above, Call the SetTimer function whenever you want the counter to start, and to print out the "DisplayedMeters" value.

With this, every .5seconds the counter will increment by 1, until it reaches the actual meters travelled

avatar image Lowpology825 Mar 30 '15 at 05:46 PM

No problem, just a little mix up on my end haha.

So I have the UpdateDisplayed setup in my Character blueprint and I have it connected to a copy of the Event Begin Play. I then am calling the DisplayedMeters in my HUD blueprint below. However the number is just staying 0 at the moment.

alt text

avatar image Lowpology825 Mar 30 '15 at 05:59 PM

I've got it working now! I just used a sequence for having multiple inputs into the Event Begin Play then I forgot to check looping on the timer!

The only thing is that after I die, the distance I guess is still updating to see if it is the actual distance. Is there a way I could make it stop even if it hasn't I guess technically reached the actual distance traveled?

avatar image skkhan Feb 25 '17 at 02:17 PM

stuck on 0

(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