The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 13 of 13

Thread: Non linear or parabolic trajectory for airplane

  1. #1
    55
    posts
    Registered User

    Non linear or parabolic trajectory for airplane

    Hey I am not sure if this is the right place to post this question but I thought I would give it a go.

    I am working on a paper airplane game that currently just uses some basic physics that would represent a projectile thrown with a certain velocity at a certain angle.

    The problem with this is that the model plane acts more like a bullet projectile then a paper airplane. I have found a few websites that talk about paper airplane aerodynamics however I don't know how I could really use them realistically in flash.

    http://www.princeton.edu/~stengel/PaperPlane.html
    http://www.paperplane.org/Aerodynamics/paero.htm

    I also saw this website that utilized loops, and that would be my ultimate goal in the end, however I dont even know where to start and see the math behind that.

    http://www.workman.com/etcetera/games/fliersclub/


    If any of you know of any tutorials that might explain close to what I am talking about, then that would be awsome! I have a pretty decent understanding of Actionscript so I can most likely work with anything you wish to share.


    Thanks for all your help in advance!

  2. #2
    How realistic do you want it to be?
    you = function(){
    setEnabled( true );
    live();
    setEnabled( false );
    }

  3. #3
    55
    posts
    Registered User
    Well ideally I would like it close to what is being achieved in that flight sim, but I am sure there were some major calculations put into it to achieve those moves. Right now my plane's trajectory is that of a canon ball.

  4. #4
    Quote Originally Posted by Neoge View Post
    Right now my plane's trajectory is that of a canon ball.
    Does your model take on an angular velocity? The plane in that sim is always moving forward, but at a certain angle (which you would use to dertermine it's rotation). In the example you showed, the angle is affected by "elevator". Notice if you set "elevator" to 0, it more or less behaves like a missile. So you just need to have the elevator variable affect your angle variable every frame.
    you = function(){
    setEnabled( true );
    live();
    setEnabled( false );
    }

  5. #5
    55
    posts
    Registered User
    Quote Originally Posted by therobot View Post
    Does your model take on an angular velocity? The plane in that sim is always moving forward, but at a certain angle (which you would use to dertermine it's rotation). In the example you showed, the angle is affected by "elevator". Notice if you set "elevator" to 0, it more or less behaves like a missile. So you just need to have the elevator variable affect your angle variable every frame.
    Hey thanks for the tip. At the moment it dosn't take angular velocity into consideration, although that might be the way to make it work. I have a lot of work cut out for me.

    I will keep you updated if I find anything.

  6. #6
    55
    posts
    Registered User
    Code:
    function updatePosition():Void {
    
    var time:Number = getTimer() - startingTime;
    
    positionX = startingX + (velocityX * time);
    
    
    positionY = startingY + (velocityY * time) - (0.5 * gravity * time * time);
    
    projectileAngle = Math.atan2(positionY - previousY, positionX - previousX);
    
    previousX = positionX;
    previousY = positionY;
    
    }
    
    function renderProjectile():Void {
    
    projectile._x = Math.floor(positionX * scaleRatio);
    projectile._y = Math.floor(positionY * scaleRatio);
    
    projectile._rotation = radiansToDegrees(projectileAngle);
    
    if(projectile._x > Stage.width || projectile._y > Stage.height) {
    endAnimation();
    }
    }
    Here is a snippet of the code. This is a version of the source from electrotank. I will continue to play around with this and see if I can come up with something, but if anyone cares to have a stab at it, go for it

  7. #7
    does this help to get you going

    Code:
     
    // think xthrust as general thrust
    var xthrust:Number;
    // think of ythrust as the angle input
    var ythrust:Number;
    // think of drag as your elevators;
    var drag:Number;
    var planeAngle:Number;
    var positionY:Number;
    var previousY:Number;
    var positionX:Number;
    var previousX:Number;
    var startX = plane_mc._x;
    var startY = plane_mc._y;
    var startRotation = plane_mc._rotation;
    reset_mc.onRelease = function() {
     delete plane_mc.onEnterFrame;
     plane_mc._x = startX;
     plane_mc._y = startY;
     plane_mc._rotation = startRotation;
    };
    start_mc.onRelease = function() {
     xthrust = Number(thrust_txt.text);
     ythrust = Number(angle_txt.text);
     drag = Number(drag_txt.text);
     plane_mc.onEnterFrame = function() {
      positionY = plane_mc._y;
      positionX = plane_mc._x;
      this._x += xthrust;
      this._y -= ythrust;
      ythrust -= drag;
      var planeDY = positionY-previousY;
      var planeDX = positionX-previousX;
      var radians = Math.atan2(planeDY, planeDX);
      this._rotation = radians*180/Math.PI;
      previousX = positionX;
      previousY = positionY;
      this._rotation;
      if (this.hitArea_mc.hitTest(ground_mc)) {
       delete plane_mc.onEnterFrame;
       this._y = ground_mc._y;
      }
     };
     planeAngle = Math.atan2(positionY-previousY, positionX-previousX);
     previousX = positionX;
    };
    Attached Files Attached Files

  8. #8
    55
    posts
    Registered User
    Hey this looks great although I can't get it to loop with your fla, but I will tinker around with this and see what turns up.

    Thanks for all your help!

  9. #9
    55
    posts
    Registered User
    Hey I have been doing some more looking around and found this.

    http://www.iwr.uni-heidelberg.de/~Mo.../kitedocu.html

    This might be useful as well. I will take a look and see if I can implement some of this code into my project.

  10. #10
    55
    posts
    Registered User
    Alright well I have an update. I was able to get loops, however it is perpetual, and I have no clue how I would go about so that it would level off based on xthrust1.

    I am sorry if the code is messy, I just wanted to get it somewhat working to boost my moral.

    Here is the function. Anyway to make it behave a little more like that flight sim?

    Thanks for your help

    start_mc.onRelease=function()
    {
    xthrust1=Number(thrust_txt.text);
    sinx = 0;
    ythrust1=Number(angle_txt.text);
    drag=Number(drag_txt.text);
    drag1=0;
    plane_mc.onEnterFrame = function()
    {
    positionY = plane_mc._y;
    positionX = plane_mc._x;
    this._x += .1 *(xthrust + xthrust1);
    this._y -= .1 *(ythrust + ythrust1) - ((drag * drag) /500);
    ythrust = drag2;
    xthrust = drag1;
    drag2 = -1 * drag * Math.cos(sinx * 180 / Math.PI);
    drag1 = -1 * drag * Math.cos(90 + sinx * 180 / Math.PI);
    //drag = drag - 1/10;
    sinx = 1/1000 + sinx;
    var planeDY = positionY-previousY;
    var planeDX = positionX-previousX;
    var radians = Math.atan2(planeDY, planeDX);
    this._rotation = radians*180/Math.PI;
    previousX = positionX;
    previousY = positionY;
    this._rotation;
    if (this.hitArea_mc.hitTest(ground_mc))
    {
    delete plane_mc.onEnterFrame;
    this._y=ground_mc._y;
    };
    };

    }
    btw: This is based off of neilmmm's code with the provided fla. You did get me in the right direction
    Last edited by Neoge; March 28th, 2008 at 07:24 AM.

  11. #11
    55
    posts
    Registered User
    any ideas on how to make it a little less perpetual? would it be handy to post the fla?

  12. #12
    55
    posts
    Registered User
    Ill just post it...
    Attached Files Attached Files

  13. #13
    55
    posts
    Registered User
    any takers?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012