Abuse Posted February 18, 2016 Share Posted February 18, 2016 Hi, I'd like to make use of the camera.movePitch(deg) and camera.moveYaw(deg) threaded functions for asynchronous camera movement. I am however currently stuck with getting the correct degree value in relationship to the player, is there any built-in API way to do this or do I need to do the calculations myself using getPosition()? Currently I am using this, but I'd prefer to use the above mentioned methods for stability reasons private void rotateCamera(Position pos){ if(!turningCam){ Runnable r = new Runnable() { //Position p = pos; public void run() { turningCam = true; camera.getCamera().toPosition(pos); turningCam = false; } }; new Thread(r).start(); } } Regards Quote Link to comment Share on other sites More sharing options...
FrostBug Posted February 18, 2016 Share Posted February 18, 2016 The math isn't too bad. Try this Position player = myPosition(); Position op = some other position; int angle = 90 + (int) Math.toDegrees(Math.atan2(-(player.getY() - op.getY()), player.getX() - op.getX())); int yaw = angle < 0 ? Math.abs(angle) : 360 - angle; 1 Quote Link to comment Share on other sites More sharing options...
Abuse Posted February 18, 2016 Author Share Posted February 18, 2016 (edited) FrostBug, it indeed wasn't too bad Position chest = getObjects().closest(dispenserID).getPosition(); Position player = myPlayer().getPosition(); double deltaX = player.getX() - chest.getX(); double deltaY = player.getY() - chest.getY(); double angleInDegrees = Math.atan2(deltaY, deltaX) * 180 / Math.PI; angleInDegrees = (angleInDegrees + 360) % 360; Just found out that the position always seems to be offset by 90 degrees. A similar solution might be worth including in the position API? Regards Edited February 18, 2016 by Abuse 1 Quote Link to comment Share on other sites More sharing options...