Angle stuff yet again

BlitzMax Forums/BlitzMax Programming/Angle stuff yet again

ozak(Posted 2006) [#1]
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?


Dreamora(Posted 2006) [#2]
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


ozak(Posted 2006) [#3]
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.


ozak(Posted 2006) [#4]
Ahh. Got it now. Just used a 3D lookat calculation. Easier since it's 3D :)



Yeah!


Dreamora(Posted 2006) [#5]
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


ozak(Posted 2006) [#6]
Yep. I figured it out. Thanks :)