Jump to content

Getting Entity camera degrees in relation to the player?


Abuse

Recommended Posts

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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