Rotating Object around Y axis with mouse drag

Hello I’m trying to rotate object with mouse drag around local Y axis when the button on rotation handle is pressed, but it’s not consistent I can’t rotate object full 360 angle and rotation is inconsistent. I’m using mousemove event with this rotation code entity.rotateLocal(0,e.dx * sensitivity,0).

Thanks in advance for help!

Code looks fine, do you have an example you can share that shows the issue or a video?

1 Like

Thanks for your response!

I attached video.

Looks like there’s a bigger issue with the project than the code you have shown. Can you please share a project with the same issue?

An example project here shows there is no issue with the code you have shown:

Also worth noting that you are trying to rotate an object by rotating a ring icon. However, your code is only using dx for the amount to rotate rather than how much your ring icon has rotated. You will need to reconsider how you do your input logic to rotate the object.

1 Like

Yeah, basically the logic right now is , when mouse enters the button ring, checks for mouse enter event and if left button is clicked. Then boolean canRotate is set to true in mouseMove function. The code above is triggered. Can you help with solution to this problem or maybe link some project with similar logic. I would really appreciate it. Thanks

I dont have an example of the exact behaviour you are looking for. You will need to share a project with the issue for others to help more easily.

As mentioned, the code you’ve used is not suitable for the control type that you’ve shown in the video.

1 Like

Hey Yaustar, I’ve created a separate project with the same logic just to keep it simple.
here is the link: PlayCanvas | HTML5 Game Engine

Thanks for help.

Office hours video:

Link to project:

I screwed up the audio recording on this one :frowning:


Thanks for help Yaustar!

Hi! @Lukas_31, in the future you could use a reparent function. You could use let distance to check the distance from the player entity with an attribute.

if(distance < number of choice) {