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.!http://www.abload.de/img/box2d_rotationinuli.png(rotation)!
I already search in this forum, right now I have this code to rotate the arrow, but the rotation-behavior is quite strange.
@var a1 = mouseX - arrowBody.x;
var b1 = mousey - arrowBody.y;
var angle = Math.atan2(a1,b1);
// var angle = angle / (Math.PI / 180);
arrow.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 -
If you are using qt 4.8.4 or older, you might be experiencing this bug.
"qAtan2 bug":https://bugreports.qt-project.org/browse/QTBUG-27090
-
bq. I think just reversing your parameters and converting to degres should be enough.
Thanks for the reply, i changed my code to:
@var angle = Math.atan2(b1,a1)
arrowBody.rotation = angle * 180 / Math.PI@The rotation works better than before but it starts at a wrong point.
The picture shows the behavior of my arrow, when I click near the orange-point the arrow changes from straight vertical to an incorrect angle!
!http://www.abload.de/img/rotation2bguhu.png(Rotation)!Thank you
-
hi,,,
i am beginner to QML i too have same problem i am creating small applications in that whenever i change the cursor position all my fishes has to come to eat the cursor point.. i am able to move it with cursor position but unable to move with direction.kindly help me
Thanku