I’m trying to create a turret that will rotate so that it is pointing at the mouse. Without the knowledge to make it happen, I sifted through tutorials until I found some code, which I adapted to my circumstances. However, the code was made to rotate towards an MC that only moved horizontally, which may be why it doesn’t work… Anyhow, here’s the code:
ActionScript Code:
[FONT=Courier New][LEFT][COLOR=#0000FF]onEnterFrame[/COLOR] = [COLOR=#000000]function[/COLOR] COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]
angle = [COLOR=#0000FF]Math[/COLOR].[COLOR=#0000FF]atan2[/COLOR][COLOR=#000000]([/COLOR][COLOR=#0000FF]_root[/COLOR]._xmouse-[COLOR=#0000FF]_root[/COLOR].[COLOR=#000080]turret[/COLOR].[COLOR=#0000FF]_x[/COLOR], [COLOR=#0000FF]_root[/COLOR].[COLOR=#0000FF]_ymouse[/COLOR], [COLOR=#0000FF]_root[/COLOR].[COLOR=#000080]turret[/COLOR].[COLOR=#0000FF]_y[/COLOR][COLOR=#000000])[/COLOR]/COLOR=#000000[/COLOR];
[COLOR=#0000FF]_root[/COLOR].[COLOR=#000080]turret[/COLOR].[COLOR=#0000FF]_rotation[/COLOR] = angle;
[COLOR=#000000]}[/COLOR];
[/LEFT]
[/FONT]
Yes, relatively simple code, but as I’m not the greatest at math, I need a little help straightening this out. Thanks for your help!