For a project, I am making a simple top down shooter and I’m trying to incorporate a push pop rotation to the player character. I am having trouble having the character image rotate to the mouse coordinates ala pointing a gun while moving.
calls classes used and loads in PVector and image data for the player class
Player player = new Player();
Screens screen = new Screens();
void setup() {
playerSprite = loadImage(“test.png”);
playerSprite.resize(100, 100);
player.playerPos.set(300, 570);
class Player {
final PVector playerPos = new PVector();
float angle = 0;
float targetAngle = 0;
float easing = 0.05f;
// player image
void displayPlayer() {
angle = atan2(playerPos.y - mouseY, playerPos.x - mouseX);
float dir = (angle - targetAngle) / TWO_PI;
dir -= round( dir );
dir *= TWO_PI;
targetAngle += dir * easing;
pushMatrix();
translate( playerPos.x, playerPos.y );
rotate( targetAngle );
image(playerSprite, playerPos.x, playerPos.y);
popMatrix();
}