First, hi! This is my first post here…
Second, the problem I’m facing is here:
The variables…
class Laserbean extends MovieClip //sic
{
var originalX:Number;
var originalY:Number;
var target:Number;
var hypotenuse:Number;
var cosine:Number;
var opposite:Number;
var adjacent:Number;
var rotation:Number;
}
Here is what the variables are supposed to do.
function onLoad() //There's other stuff in the onLoad() and onEnterFrame() functions, but they're irrelevant afaik
{
this._x = (Math.random()*500)+25;
this._y = (Math.random()*50)+50;//fairly obvious, chooses a random place to spawn
originalX = this._x;//stores spawn point x so's not to mess up calculations when it starts moving.
originalY = this._y;//stores spawn point y
target = Math.round(Math.random()*550)//Picks a random point on the x-axis to aim for
}
function onEnterFrame()
{
opposite = target-originalX // Starts to draw a virtual triangle using start point and target as references
adjacent = 300-originalY;
hypotenuse = Math.sqrt(Math.pow(opposite,2)+Math.pow(adjacent,2)); //Pythagoras' method for finding hypotenuse.
cosine = adjacent/hypotenuse; // SOH, CAH, TOA ^_^
rotation = Math.acos(cosine); //gives angle in radians
this._rotation = rotation*Math.PI/180; //Changes rotation of MovieClip sp it faces target, converting radians into degrees
}
well…that’s how it’s supposed to work. In actual fact it does nothing.
Where the problem doesn’t lie:
Opposite variable works fine
Adjacent variable works fine.
Thanks for any help you can give!
PS I’m very new to Flash, this is the first game I’ve created and other than this chunk of code it’s working fine - I haven’t come across any other bugs I can’t correct. If you think that this kind of thing is too advanced for me right now(i.e., my code is so messed up it doesn’t even begin to make sense), I’ll take your advice and leave this class of enemy out of the finished game.
EDIT:OK, still haven’t found the error. Giving up on this for a bit…lameness.