Rotation based on Mouse-Position

Hello Community 😉

I am working on a little game (similar to frozen bubble), and I have a problem with the rotation of the Arrow, which shows the direction to shoot.
The arrow on the bottom of the image, should alwas point to the current position of the mouse-cursor.
Image

I already search in this forum, right now I have this code to rotate the arrow, but the rotation-behavior is quite strange.

Code: Select all

   
var a1 = mouseY - arrowBody.y;
var b1 = mouseX - arrowBody.x;
var angle = Math.atan2(a1,b1);
// var angle = angle / (Math.PI / 180);
arrowBody.rotation = angle;


As you can see in the code, I also tried to work with degrees, but nothing worked for me.

I hope you can help me!
Thank you,
nor0x
I think you are on the right track. Keep in mind though, that the atan2 function might consider the 'east' position to be zero, not the 'north' position.
You also need to mention which Javascript port you are using... for example box2dweb would do body.SetAngle( xxx ), not body.rotation = xxx;
Thanks for your Reply!
I changed east to zero, but again strange behavior of the arrow.

I use the V-Play-Engine, it's a quite new project, based on QT with Javascript Support and Box2D included, i don't know which port it is - sorry!
But there is no body.SetAngle(xxx) method available.

Original thread: https://box2d.org/forum/viewtopic.php?t=9048