Jump to content

Getting Entity camera degrees in relation to the player?


Recommended Posts

Posted

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

Posted (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 by Abuse
  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...