A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [F8] Maths/Rotation Problem

  1. #1
    Rock Your Face Off.
    Join Date
    Nov 2006
    Location
    UK
    Posts
    56

    [F8] Maths/Rotation Problem

    Hi folks,

    Hope everyones well and good! I am currently working on a new game, its quite classic in its nature - harking back to classic coin-munchers such as space invaders, galagga and Atlantis. Anyway, the game involves a ship orbiting a planent in the centre of the screen.

    So far I have the basic code in place to make the ship orbit the planet:

    ///***Ship Movement Setup***///
    var radius = 200;
    var speed = 2
    var xcenter = ship._x;
    var ycenter = ship._y;
    var degree = 0;
    var radian;

    function onEnterFrame(){
    degree += speed;
    radian = (degree/180)*Math.PI;
    ship._x = xcenter+Math.cos(radian)*radius;
    ship._y = ycenter-Math.sin(radian)*radius;
    ship._rotation = ship._x+ship._y
    }
    ///***///***///***///
    stop();
    what I'd really like is for the rotation of the ship to compensate for its orbit. ie. I'd like the ship to permanently face outward (so it can shoot baddies!)

    Can anyone think of a bit of math that could achieve this?

    If anyone can help that would be very much appreciated!

    thanks

  2. #2
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    ummm well you could flip the ships image around or change its registration point from the front of the movie clip to the rear and see if that helps.
    ~calmchess~

  3. #3
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    hi this attachment should help u out
    Last edited by silentweed; 11-22-2007 at 07:14 PM.
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  4. #4
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    927
    you have to make ship._rotation go full circle as it goes around the planet
    who is this? a word of friendly advice: FFS stop using AS2

  5. #5
    Senior Member Speed85's Avatar
    Join Date
    Apr 2007
    Posts
    292
    Well, you already have the degree relative to the planet, would it be the right degree if you added/subtracted that degree to the _rotation of the ship?

    I'm really tired so it seems to work in my head, but dunno if it really works.
    Whoever taught EVERYONE to put all their code on movie clips needs to be shot...

  6. #6
    Rock Your Face Off.
    Join Date
    Nov 2006
    Location
    UK
    Posts
    56
    Thanks so much for the help guys! I had no idea I was getting any responses since I stopped getting email notifications from the board for some reason!

    I've fixed my rotation problem now thanks to your help!

    Cheers!

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