Question

How do I make my character strafe? He is always facing the mouse

        this.rotation = Math.atan2((stage.mouseY - this.y), (stage.mouseX - this.x)) * 180/ Math.PI + 90;

How do I make him strafe to the left when holding down a key?

            if(leftKeyDown)
            {
                if(!this.hitTestObject(_root.container_wall))
                {
                    gotoAndStop(2);
                    //WHAT TO TYPE HERE?
                }
            }

No correct solution

OTHER TIPS

As i know...

for left

x += Math.cos((rotation + 90)*Math.PI/-180)*speed;
y += Math.sin((rotation + 90)*Math.PI/-180)*speed;

for right

x += Math.cos((rotation - 90)*Math.PI/-180)*speed;
y += Math.sin((rotation - 90)*Math.PI/-180)*speed;

for back

x += Math.cos((rotation + 180)*Math.PI/-180)*speed;
y += Math.sin((rotation + 180)*Math.PI/-180)*speed;

for forward

x += Math.cos((rotation)*Math.PI/-180)*speed;
y += Math.sin((rotation)*Math.PI/-180)*speed;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top