I am very inexperienced with AS3, and I am even newer to Flashpunk. I am trying to make my character rotate to face the mouse. All tutorials I have found have said to find the difference between the x and y positions of the mouse and character and then do some math to find the number of radians the character needs to rotate. Well, I understand that flashpunk uses degrees instead of radians, so I set the angle of the character to the cotangent of the slope of the line between the character and the mouse. I also set the origin of my character graphic to be at the center, yet, when I test my game, the character moves (as opposed to just rotating) and doesn’t face the mouse. I am at my wit’s end, and I would greatly appreciate some help. Here is my code:
package
{
import net.flashpunk.Entity;
import net.flashpunk.graphics.Spritemap;
import net.flashpunk.utils.Input;
import net.flashpunk.utils.Key;
import net.flashpunk.tweens.misc.AngleTween;
import Math
public class Player extends Entity
{
public var sprPlyr:Spritemap = new Spritemap(Assets.Plyr, 64, 64);
public var xd:Number = 0;
public var yd:Number = 0;
public var degangle: Number = 0;
public function Player()
{
graphic = sprPlyr;
}
override public function update(): void
{
if (Input.check(Key.A)) { x -= 1 };
if (Input.check(Key.D)) { x += 1 };
if (Input.check(Key.W)) { y -= 1 };
if (Input.check(Key.S)) { y += 1 };
sprPlyr.originX = 32;
sprPlyr.originY = 32;
xd = Input.mouseX - sprPlyr.x;
yd = Input.mouseY - sprPlyr.y;
degangle = 1 / Math.tan(yd / xd);
sprPlyr.angle = degangle;
}
}
}