[GD5] Displaying Player's Speed on the Example Platformer

Hi folks,

I’ve enjoyed exploring GDevelop so far, but I’ve run into a problem that seems very simple but that I can’t fix.

I would like to display the Player’s current speed in the top left of the screen.

I have a text object, KMH, which I manipulate with the following event:

(no condition) Do = ToString(PlayerHitBox.LinearVelocityX()) to the text of KMH

This doesn’t work. I’ve tried a number of alternatives, including writing Player instead of PlayerHitBox, and writing Speed, LinearVelocity, AngularVelocity and Longueur instead of LinearVelocityX.

None of these work. I feel like I’m missing something obvious and I’m hoping you can help me out.

Here’s the example: link

It can’t be done, but here is a workaround (valid for web only, it uses JS):
GetPlatformerSpeed.zip (6.98 KB)
Impossible to do in C++, because the “currentSpeed” member/variable is private :frowning:

Thanks Lizard-13, I opened it up in GD4 and it looks great!

When I go to “Choose and add an event” in GD5, I can select Javascript code, but it says: “Unknown event of type BuiltinCommonInstructions::JsCode”.

Does this mean I’m not set to web-only, or something like that?

As a workaround, I am currently recording the player’s X position at each interval, and comparing the two to get a speed.

Yeah, it’s almost the same, I’ve made a comparison here:
GetPlatformerSpeed.zip (7.47 KB)
It compares the speed from my code and the speed from the expressions, as you are doing. And as you can see in the test, the max difference between both methods is almost zero (~E-12 in my PC). Sometimes there is a great difference when you collide with a wall, but it’s is just for one frame :slight_smile: