Rotate camera on button being pressed

Hi i have been struggling creating button that’s function is to rotate camera around when it is being pressed.

Hi @Lukas_Zahumensky,

A good starting point in adding UI buttons is the following example:

https://developer.playcanvas.com/en/tutorials/ui-elements-buttons/

You can add your custom logic to rotate an entity when the button is pressed or released.

You may find this example useful as well, it showcases how to rotate an entity using the mouse:

https://developer.playcanvas.com/en/tutorials/rotating-objects-with-mouse/

1 Like

well i have created UI with buttons but I am not able to manage how to make camera rotate only if I hold the exact button pressed.

Try sharing your project or at least a sample project that reproduces your issue to take a look!

https://playcanvas.com/project/816336/overview/360uiexample
this may be the case :slight_smile:
i need to make camera rotate as the let’s say left arrow button is being pressed

1 Like

Hi @Lukas_Zahumensky,

Looking at your code, it seems like you’re on the right track, but there are some adjustments you might want to consider making. You initial approach to have a variable that is tracked in the update function that is affected by button events is correct.

I see that you are also subscribing to the button event in the update function. This is not necessary and should be moved to initialize since repeatedly adding listeners can be quite costly.

I personally would separate your keyboard and button press scripts to make it easier to manage. You could then create a boolean script attribute in your button script that determines whether the button moves the camera left or right on click and multiply your Euler values appropriately.

I hope this is helpful.

2 Likes