Angle stuff yet again
BlitzMax Forums/BlitzMax Programming/Angle stuff yet again
| ||
Hi. Im having a robot at a given world position and a mouse controlled target object at another position. I want to know the angle between the robot and the target so I can rotate the object to face the target cursor. I've tried a few solutions posted here, but none of them work. Anyone? |
| ||
angle:double = atan((mousey()-roboty)/ float(mousex() - robotx)) or angle:double = atan2(mousey()-roboty, mousex() - robotx) That angle is always to the horicontal so x axis. Depending on x difference > 0 or < 0, this means right or left and according reaction in your "in which direction do I need to turn the robot" handling |
| ||
Hmm. This only gives me from 0..180 rotation. I need the angle between two objects in the world. Not from the mouse. I found the sample that rotates a box towards the mouse, but it does not work in my case. This is in 3D using MiniB3D btw. |
| ||
Ahh. Got it now. Just used a 3D lookat calculation. Easier since it's 3D :) Yeah! |
| ||
ozak: the angle can't be larger than 180 degree. if it was then the other way round it would be shorter as 360 - X with X > 180 -> remaining << 180 |
| ||
Yep. I figured it out. Thanks :) |