Hey @Albertos i check out the project, it uses the same formula i mention above with a sight changing
Math.atan2(x- current.x, - (y - current.y)) * (180 / Math.PI)
Current being the ui element axis
I did that with my project but it doesnt seem to work.
The main difference between the two project is, he is using 3d object to lookat, and i m using mouse corrdinates as the direction for lookat.
Here is the link to a Forked project, it has no extra staff, feel free to take a look,dug in, fork it even, and let me know if I can achieve this somehow
You first need to bring the reported touch/mouse position and the position of the UI element to a single frame of reference. For example, the UI element position Y component starts at the bottom, and grows as it goes up, while touch Y component starts at the top and grows as it goes down. Simply add/substract needed width/height from touch position, so that it matches with the UI element position when you click it. Without it, you cannot calculate the angle, as the vectors are not aligned.
I also noticed you do something like this.entity.up.mulScalar(scalar). This will modify up vector of the entity in place. Do not do that. If you need to use entity.up copy it to a temp vector and modify the temp vector then. Also, in your case, you should just create a temp vector [0, 1, 0] and then scale that one - all children will align properly, regardless of parent’s orientation.