3

So I'm traveling very far in the end by elytra with firework rockets and sometimes there are vast gaps and i would like to know my speed because I usually use the islands below to regulate my speed: If you go at approximately 40 degrees down to build speed, then approximately 40 degrees up you can go a very long while without using a firework rocket.

But without the islands, it's pretty hard to tell how fast I'm going. I know I'm probably wrong but I assume I can set an objective and use a scoreboard?

1 Answer 1

3

This is an interesting problem and I think I got a solution for you.

Speed is the difference in position per time interval. This means that if you can measure travel distance and time, you can measure speed.
It turns out that you can indeed track both distance and time as follows:

/scoreboard objectives add travelDistance stat.aviateOneCm

This scoreboard objective keeps track of how many centimeters you have flown. Now you need to keep track of the time. This can either be using redstone or a scoreboard timer. I leave it up to you to design that, since it is out of the scope of this question.

Now you need an additional objective to write the speed to.

/scoreboard objectives add speed dummy Speed

Following commands should be repeated every second, using your timer:

/execute @a ~ ~ ~ scoreboard players operation @s speed = @s travelDistance
/scoreboard players set @a travelDistance 0

If you repeatedly execute these last two commands, then you get the distance in centimeters that the player travels within the specified timeinterval. That's exactly the definition of speed!

Make sure that you display the Speed scoreboard in the sidebar and you're set!


For the sake of completion(and because it was suggested), here is how you convert your value to a different unit. I am making the following assumptions:

  • There exists a scoreboard, containing constants. I name it Constants
  • This scoreboard has a constant called timeUnit with value 3 600
  • This scoreboard has a constant called distanceUnit with value 100 000
  • You want to convert to a speed in Km/h
  • Your initial value is in cm/s

If you convert to a different unit, you have to do divisions and multiplications. It is important that you do divisions after multiplications, because scoreboards don't work with floating point values. To convert from cm/s to km/h, you have to use following commands:

/scoreboard players operation @a speed *= timeUnit Constants
/scoreboard players operation @a speed /= distanceUnit Constants

These commands should be pasted right after the other commands that got repeated. If you want a different unit, then you have to alter the values of the constants.

2
  • Neat idea. OP wants to use elytra so I think you need to use aviateOneCm. I think flyOneCm is just for creative flying. With another operation or two, it could be converted to km/hr.
    – IronAnvil
    Commented May 18, 2018 at 3:58
  • @JeffiBoye If my answer solved your problem, then please accept it using the checkmark at the left-hand side. That will reward me for answering your question and it will let other people know that your question is answered, so that they don't have to ask it for themselves. Everybody gains like that.
    – D-Inventor
    Commented Jun 12, 2018 at 19:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.