Lovera
Lovera

Reputation: 192

Libgdx Coordinates after rotateAround camera

After the camera rotation, the coordinates were confusing to me.

I have a camera a character and a map. This player walks only in the directions: north (90 °), south (270 °), east (0 °), west (180 °).

Before rotation

After rotating the camera from the position of the player 'camera.rotateAround (..., ..., ...)' the player starts to move in new directions as a result of rotation.

After rotation

Is there a way to reposition the original back to the coordinates without moving the map to the original position?

I appreciate the help.

Upvotes: 2

Views: 293

Answers (1)

Deniz Yılmaz
Deniz Yılmaz

Reputation: 1094

First you need to store rotation angle of map. Then when player moves you need to take account rotation angle of map.

camera.rotatearound(...)//I guess you rotating +90 or -90 in this game 
maprotation+=... //+90 or -90 depends on side you turn.
//i ll assume rotation direction is counter clock wise. 

Now you know rotation so you can set player movement with a trigonometry.

in player.moveup(float maprotation) method or whereever you wrote codes for moving to north.

x+=MathUtils.cosDeg(90-maprotation)*speed;//90 degree for moving up
y+=MathUtils.sinDeg(90-maprotation)*speed;// - maprotation for correction 

enter image description here

As you can see when camera rotating also directions rotating. So you just need to subtract map rotation to correct.

enter image description here

Upvotes: 1

Related Questions