Stop/start rotate my Cube


Hi, I’m new to code and Playcanvas, so my problem may seem very simple, but I would like to rotate my entity on click with a start/stop button

I tried to fork the project with the html/css ui , and add the object rotation to the click but it doesn’t seem to work.

If you know how to do it, I’m a taker!


Hi @huricane and welcome!

I see you use dt (delta time) in your event. Normally this is only used in the update function. I guess dt is undefined here and undefined * 90 is probably 0 or NaN. I suggest to replace dt * 90 with just 90.

If you want to rotate the cube by delta time instead, I would toggle a boolean with your button and rotate the cube in the update function (with using dt), if this boolean is true.

Hey !

I tried this
error 2

But when i click on the button my obj don’t turn, i don’t understand why, maybe i focus the wrong entity ?

Are you sure box isn’t with a uppercase letter?

i don’t think so , i just forked this one HTML/CSS UI | Learn PlayCanvas

I tried it myself and actually it works. The problem is probably that you can’t see it works. Try to rotate it with 45 degrees.

okay I do understand that’s work fine for me too, but I do what I would like the object to continue rotating until I press the button again

Then you have to apply this suggestion.

Okey i will try it thanks!

Below an example.

1 Like