A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Using an object angle to calculate x & y values

  1. #1
    Junior Member
    Join Date
    Mar 2005
    Location
    Canterbury
    Posts
    22

    Using an object angle to calculate x & y values

    I need to move an object forward at the angle that it's pointing. Say you want a ship to move forward based on it's angle - the ship has x and y coordinates (lets say shipx and shipy), an angle (say shipangle) and a speed (shipspeed): some maths has to be done to create a new position each time. I figured out a long-winded way of doing it but I think there should be a simple equation I don't know yet (maybe something to do with sines and copsines?).

    Thanks in advance.

  2. #2
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    some usefull links to solve such things in future:
    http://www.codylindley.com/Tutorials/trigonometry/
    http://www.kirupa.com/developer/acti...igonometry.htm
    http://www.adobepress.com/articles/a...p?p=30617&rl=1
    http://www.albinoblacksheep.com/flash/trig

    PHP Code:
    function moveShip(angle){
        var 
    radians angle* (Math.PI/180);
        var 
    speed 2;
        
    ship._x+= Math.cos(radians)*speed;
        
    ship._y+= Math.sin(radians)*speed;
    }
    _root.onEnterFrame = function(){
        
    moveShip(_xmouse-Stage.width/2);


  3. #3
    Junior Member
    Join Date
    Mar 2005
    Location
    Canterbury
    Posts
    22
    Thanks for that, seems simple, I'll follow it up!

    ADE

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