A Flash Developer Resource Site

Results 1 to 19 of 19

Thread: Moving ball between two points... atan2?

Threaded View

  1. #1
    Senior Member
    Join Date
    Aug 2007
    Posts
    291

    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:
    picture

    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(atanYatanX)
    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_FRAMEmoveGuy);

    function 
    moveGuy(e:Event):void
    {
         
    guy_mc.+= xSpeed;
         
    guy_mc.+= ySpeed;

    Someone please look at this and tell me what I'm doing wrong.
    Last edited by Taidaishar; 03-25-2008 at 04:13 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center