Moving ball between two points... atan2?
Hey guys. I'm getting really frustrated with this. I created a little flash document to help me understand how to use Math in Flash to move an object to a target X and Y at a constant speed, and I can't seem to get ANYTHING to work. This is what I have so far... first, I've attached an image of the app I'm creating:
picturehttp://farm3.static.flickr.com/2306/...c8b48fe5_o.jpg
basically, I just put in the number of the point (1-4) and have the ball move to that point. Everything works except for the trajectory of the ball. I've got the angles right because when I set the rotation of the ball equal to the angle that I get, the black dot lines up with whichever blue line applies. The only problem is, the speed is messed up. Here's what I need help with:
PHP Code:
atanX = (targetX - startX);
atanY = (targetY - startY);
angle = Math.atan2(atanY, atanX)
angle = Math.round(angle/Math.PI * 180);
var speed:Number = 4;
xSpeed = Math.cos(angle)*speed; //these are the two lines
ySpeed = Math.sin(angle)*speed; //that must be wrong
guy_mc.rotation = angle;
this.addEventListener(Event.ENTER_FRAME, moveGuy);
function moveGuy(e:Event):void
{
guy_mc.x += xSpeed;
guy_mc.y += ySpeed;
}
Someone please look at this and tell me what I'm doing wrong.