A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: unbalanced forces

  1. #1
    Junior Member
    Join Date
    Jun 2002
    Posts
    4


    The above graphic illustrates a problem I have. It is a problem involving unbalanced forces. Currently, the ballon should be moving down and to the right. As you click the arrows, it should increase the numbers in the boxes and the force in that particular direction.

    When the forces are equal, the balloon should stop moving.

    In order to move the balloon upwards, you should be able to click on the air pressure arrow. When the value for air pressure is greater than the value for gravity, the balloon should float.

    In order to move the balloon to the left (West), the right arrow should be clicked until its force is greater than the force to the right (to the east).

    Any one have any ideas on how this could be accomplished?

    Brian

  2. #2
    Senior Member
    Join Date
    Jan 2002
    Posts
    368
    each of these forces would be computed as an acceleration.
    all forces would be added to the x and y velocities of the baloon. then the velocities would be added to the position of the balloon.

    set up four variables, suchas:

    lift
    gravity
    westwind
    righwind

    have your arrows increase or decrease those values.
    then add those values to the velocity:

    xVelocity+=gravity;
    xVelocity+=lift;
    yVelocity+=westwind;
    yVelocity+=rightwind;

    then add your velocity to the position:

    balloon._x+=xVelocity;
    balloon._y+=yVelocity;

    note that gravity would be a positive force, lift would be negative. westwind would be neg, righwind pos.

  3. #3
    Junior Member
    Join Date
    Jun 2002
    Posts
    4
    Thanks. I did some digging around the Flash MX samples, and found one called movement-thrust.fla. It had a script very similar to the one I was looking for. I did some tweaking, and this is the script I came up with:

    onClipEvent (load) {
    // declare and set initial variables
    thrust = 1;
    decay = 1;
    maxSpeed = 10;
    xthrust = 1;

    }
    onClipEvent (enterFrame) {
    // move right or left
    //
    //
    if (Key.isDown(Key.RIGHT)) {
    // calculate speed
    xSpeed += xthrust;
    // trace (xSpeed)
    flames._visible = 0;
    }
    if (Key.isDown(Key.LEFT)) {
    // accelerate in the negative direction
    xSpeed -= xthrust;
    // trace (xSpeed)
    flames._visible = 0;
    }
    //
    if (Key.isDown(Key.UP)) {
    ySpeed += thrust;
    // trace (ySpeed)
    }
    if (Key.isDown(Key.DOWN)) {
    // trace (ySpeed)
    ySpeed -= thrust;
    }
    // maintain speed limit
    speed = Math.sqrt((xSpeed*xSpeed)+(ySpeed*ySpeed));
    if (speed>maxSpeed) {
    xSpeed *= maxSpeed/speed;
    ySpeed *= maxSpeed/speed;
    }
    //
    // move person based on calculations above
    _y -= ySpeed;
    _x += xSpeed;
    trace (xSpeed);
    trace (ySpeed);
    //
    }


    So basically, when I add this script to a movie clip, it moves the clip around the screen with the arrow keys. My problem now is trying to get the values for gravity, airpressure, and the two winds to be displayed. Is it possible to use the trace command, as I have done above, to display the values for those forces? If not, what would you suggest?

    A friend suggested dynamic text, but I don't know how that would work.

    Thank you.

    Brian

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