# Limited character flight with actionscript

**URL:** <https://forum.kirupa.com/t/limited-character-flight-with-actionscript/281101>\
**Category:** Uncategorized\
**Created:** [February 4, 2009, 9:51pm UTC](https://forum.kirupa.com/t/limited-character-flight-with-actionscript/281101 "2009-02-04T21:51:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![felixirDesign](https://avatars.discourse-cdn.com/v4/letter/f/c57346/32.png) [@felixirDesign](https://forum.kirupa.com/u/felixirDesign)\
**Post date:** [February 4, 2009, 9:51pm UTC](https://forum.kirupa.com/t/limited-character-flight-with-actionscript/281101/1 "2009-02-04T21:51:03Z")

</div>

Hi all, i am creating a flash project that uses a character with limited flight. the idea is that the character has a set amount of time that they can fly for, say 3 seconds and then they run out of power and the power will recharge once they let go of the button but will re-charge at a slower rate than used but i have run into trouble. if anyone can point me in the right direction that would be great. here is my code

var yspeed = 0;  
var xspeed = 0;  
var gravity = 0.6;  
var rotationspeed = 0;  
var power = 1.6;  
var flightPower = 1.6;  
var friction = 0.9;  
var flightTime = 3;  
var curFlightTime= 3;  
onEnterFrame = function() {  
yspeed += gravity;  
xspeed _= friction;  
this.\_x += xspeed;  
rotationspeed = friction;  
this.\_rotation = 0+rotationspeed;  
if (this.\_y\<=400-this.\_height/2) {  
this.\_y += yspeed;  
if (Key.isDown(Key.LEFT)) {  
xspeed -= power;  
rotationspeed += powerxspeed/2;  
} else if (Key.isDown(Key.RIGHT)) {  
xspeed += power;  
rotationspeed += power_xspeed/2;  
}  
} else {  
xspeed \*= friction;  
yspeed = 0;  
this.\_y = 400-this.\_height/2;  
}

[COLOR=Purple]//trouble starts here[/COLOR]  
if (Key.isDown(Key.UP)) {

```
yspeed -= flightPower;
curFlightTime=flightTime--;
countDown = function () {
     flightTime--;
     if (flightTime == 0) {
         flightPower = 0.2;
             }

}    
timer = setInterval(countDown, 500);

```

}else{  
powerBack = function (){  
flightTime = flightTime +0.1;  
flightPower= 1.6;  
if (flightTime \>=3){  
flightTime=3;  
}  
}  
timer = setInterval(powerBack, 500)  
}  
[COLOR=Purple] //and ends here[/COLOR]  
if (yspeed\<0) {  
yspeed \*= friction;  
}  
}
