Ask here your questions to get help using GDevelop.
User avatar
By Sanglorian
#63995 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.
User avatar
By Lizard-13
#64169 It can't be done, but here is a workaround (valid for web only, it uses JS):
(6.98 KiB) Downloaded 69 times

Impossible to do in C++, because the "currentSpeed" member/variable is private :(
User avatar
By Sanglorian
#64195 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.
User avatar
By Lizard-13
#64203 Yeah, it's almost the same, I've made a comparison here:
(7.47 KiB) Downloaded 78 times

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 :)