PDA

View Full Version : chopper like decceleration



nitras
June 25th, 2006, 03:57 PM
Hi it's sunday so i am experimenting again


trying to build a realistic helicopter blade movement

the acceleration works fine

but when i loose hold of the button that has been pressed
i'd like it to see reach an max value
then when the button is released it slowly deccelerates to zero

can anyone point me to what i am doing wrong?



var velocity:Number = 1;
var break:Number;
var maxvelocity:Number = 50;
velocityt.text = 0;
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
if (Key.isDown(Key.UP)) {
velocity += 0.2;
wiek._rotation += 1+velocity;
trace("new :"+Math.round(velocity));
velocityt.text = "velocity : " + Math.round(velocity);
if (Math.round(velocity) == maxvelocity) {
trace("final vel "+Math.round(velocity));
velocityt.text = "velocity : " + Math.round(velocity);
maxvel.text = "maximum reached"
stat.text = "lift off";
wiek._rotation = maxvelocity;

} else {
("decceleration"+Math.round(velocity));
brake = 7;
wiek._rotation -= velocity/brake;
}
}
};
Key.addListener(keyListener);

Joppe
June 25th, 2006, 04:58 PM
Try using onenterframe loop instead of key listener

dal platinum
June 27th, 2006, 11:25 AM
I might be wrong here, but there doesn't seem to be anything in there for what happens when Key.isDown(Key.UP) is false. Which would explain why it isn't working.

Is the }else { statement in the right place? I would have thought it would be more like:


keyListener.onKeyDown = function() {
if (Key.isDown(Key.UP)) {
velocity += 0.2;
wiek._rotation += 1+velocity;
trace("new :"+Math.round(velocity));
velocityt.text = "velocity : " + Math.round(velocity);

if (Math.round(velocity) == maxvelocity) {
trace("final vel "+Math.round(velocity));
velocityt.text = "velocity : " + Math.round(velocity);
maxvel.text = "maximum reached"
stat.text = "lift off";
wiek._rotation = maxvelocity;
};

} else {
("decceleration"+Math.round(velocity));
brake = 7;
wiek._rotation -= velocity/brake;
}

};

?

Not sure if this helps. Just the first thing that came to mind after looking at it.