Hi!
I am Montana.
For 4 years, I have been looking for a rotation code. This code will allow you to walk in different directions in a Virtual World.
I have found it, but it is laggy.
Do any of you know the code?

Hi!\r\nI am Montana.\r\nFor 4 years, I have been looking for a rotation code. This code will allow you to walk in different directions in a Virtual World.\r\nI have found it, but it is laggy.\r\nDo any of you know the code?

If you want to make a character move in the direction they are facing in a 2D world from a topdown perspective, you can use basic trigonometry to calculate the amount that they should move in the x/y directions based on their rotation. The Pythagorean theorem does the trick.

Flash stores it's rotational data in radians, which need to be converted into degrees (hence the Pi/180 part of the formula).

If you want to make a character move in the direction they are facing in a 2D world from a topdown perspective, you can use basic trigonometry to calculate the amount that they should move in the x/y directions based on their rotation. The Pythagorean theorem does the trick.\r\n\r\nthis._y = this._y + (speed*sin(rotation*(3.14159/180)));\r\nthis._x = this._x + (speed*cos(rotation*(3.14159/180)));\r\n\r\nFlash stores it's rotational data in radians, which need to be converted into degrees (hence the Pi/180 part of the formula).

And a clarification on conversions:
Degrees to radians: Divide by 180 Multiply by PI
Radians to degrees: Multiply by 180 Divide by PI

Depends on what you want.\r\n\r\nIf you want to use the mouse:\r\n\r\n[i]player.radians = Math.atan2(_ymouse-player._y,_xmouse-player._x);\r\nplayer._rotation = player.radians*180/Math.PI;\r\nplayer._x += Math.cos(player.radians)*player.speed;\r\nplayer._y += Math.sin(player.radians)*player.speed;[/i]\r\n\r\nOtherwise, you can just use the conversion from degrees to radians from the rotation:\r\n\r\n[i]player.radians = player._rotation/180*Math.PI;\r\nplayer._x += Math.cos(player.radians)*player.speed;\r\nplayer._y += Math.sin(player.radians)*player.speed;[/i]\r\n\r\nAnd a clarification on conversions:\r\nDegrees to radians: Divide by 180 Multiply by PI\r\nRadians to degrees: Multiply by 180 Divide by PI