More realistic movement
Hello and welcome to "Lesson 4",
In this lesson we looked at "More realistic motion."
We use the following code:
onClipEvent (load) {
power = 0.3;
ys = 0;
xs = 0;
friction = 0.95;
gravity = 0.1;
thrust = 0.75;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
xs -= power;
}
if (Key.isDown(Key.RIGHT)) {
xs += power;
}
if (Key.isDown(Key.UP)) {
ys -= power*thrust;
}
if (Key.isDown(Key.DOWN)) {
ys += power*thrust;
}
xs *= friction;
ys += gravity;
_y += ys;
_x += xs;
}
So as you can see it is no longer just as easy to move left and right as it is up!
For rotation replace:
xs *= friction;
ys += gravity;
_y += ys;
_x += xs;
with:
xs *= friction;
ys += gravity;
_y += ys;
_x += xs;
_rotation += xs;
to make it rotate when moving along the xaxis (left and right)