I'm trying to return a point from a method that calculates angle as a vector.
I'm then adding this points x & y to my player object (from example code)'s x and y Numbers - these are Numbers, not a point. In other places I see numbers defined as floats, so I didn't expect this to be a problem.
When I multiply distvar and distvar2 by * 2, then my object move, best I can tell because the values, formerly .59~ & -.8~, are greater than 1 (absolute value).
Any hints? Should I just use a Point variable on my player object instead? Is there something else I must do to convert from a point.x/y to a Number? New to flash, appreciate your help.
Thanks!
public function GetAngle(initialp:Point,secondp:Point):Point{
distvar = ((initialp.x - secondp.x) * (initialp.x - secondp.x));
distvar2 = ((initialp.y - secondp.y) * (initialp.y - secondp.y));
//Emergency guard clause against dividing by 0
if (distvar + distvar2 == 0){
distvar = 1;
distvar2 = 1;
}
veldistance = Math.sqrt((distvar+distvar2));
distvar = ((Math.abs(initialp.x-secondp.x))/veldistance);
distvar2 = ((Math.abs(initialp.y-secondp.y))/veldistance);
if (secondp.x < initialp.x){
distvar = -distvar;
}
if (secondp.y < initialp.y){
distvar2 = -distvar2;
}
apoint.x = distvar;
apoint.y = distvar2;
return apoint;
The values of a point.x/y are numbers. The way you are adding the point.x/y to your object.x/y should be fine. I suspect there is something else wrong with the code, though without more of your code I'm not sure what. For one, I can't see where apoint is created.