[SOLVED] How to make a circle in the ui rotate depending on speed in the Vehicle Physics tutorial?

I have tried using this.entity.rotate(0, 0, this.speed*dt) in which case my variable is speed and it just disappears I wanted to know if anybody knows a better way to make this work with the Vehicle Physics tutorial

Hi @DeductedFlame24,

Can you provide more detail on how you have your entity set? The method you posted should work correctly as long as the this.speed is a numeric value, and rotate an entity along the Z axis.

Which is correct for UI elements.

I have it as a part of a 2d screen

It should work then, if it doesn’t try posting a sample project to take a look at.

ok will post one if i cannot make it work

1 Like

I added you if you want to test or fix anything

@DeductedFlame24, when your project is quite big, post some instructions on how to find and reproduce the problem.

  1. Scene to open
  2. Entity in question
  3. Script in question

Helps tons debugging this quickly :wink:

oh sorry, the scene is untitled, the entity is speedometer inside which is in speedometer outside which is in HUD and the Script is speedometer.js

Your this.speed property was undefined, so there was no actual rotation happening.

I’ve updated your script to this, so now it rotates depending on the speed of the vehicle. This is good to test not perfect, since these are different values. Of course you can’t see the circle rotating since … it’s black :slight_smile: Put a different texture there!

Speedometer.prototype.initialize = function() {
    this.vehicleScript = this.car.script.vehicle;

// update code called every frame
Speedometer.prototype.update = function(dt) {
    this.entity.rotate(0, 0, this.vehicleScript.speed*dt);                   
1 Like

Thank you so much @Leonidas very appreciated