I’ve come across an unknown glitch in the development of my game. If you check out the .swf, you’ll notice then when you move left or right in roll mode, the guy bounces. Note that while moving, the guy also rotates. Here is the code:
onClipEvent (load) {
// movement variables
standacc = 1;
rollacc = 0;
friction = 0.96;
thrust = 1;
// jumping variables
jumping = false;
yspeed = 0;
gravity = 2;
floor = this._y;
// misc. variables
scale = 30;
Mode = "standing";
actions = ["stand", "walk", "bounce", "slam"];
action = actions[0];
// initialization
this._xscale = scale;
this._yscale = scale;
}
onClipEvent (enterFrame) {
// standing mode
if (Mode == "standing") {
// self-ran
rollacc = 0;
this._rotation = 0;
if (!jumping) {
this.gotoAndStop(action);
} else {
this.gotoAndStop("bounce");
}
if (!Key.isDown(Key.RIGHT) && !Key.isDown(Key.LEFT)) {
action = actions[0];
}
// movement
if (Key.isDown(Key.RIGHT)) {
this._xscale = scale;
this._x += standacc;
action = actions[1];
}
if (Key.isDown(Key.LEFT)) {
this._xscale = -scale;
this._x -= standacc;
action = actions[1];
}
}
// rolling mode
if (Mode == "rolling") {
// self-ran
this.gotoAndStop("roll");
// movement
this._x += rollacc;
rollacc *= friction;
this._rotation += rollacc*2;
if (Key.isDown(Key.RIGHT)) {
this._xscale = scale;
rollacc += thrust;
}
if (Key.isDown(Key.LEFT)) {
this._xscale = -scale;
rollacc -= thrust;
}
// jumping
if (Key.isDown(Key.UP) && !jumping) {
jumping = true;
yspeed = 20;
}
if (jumping) {
this._y -= yspeed;
yspeed -= gravity;
}
if (this._y>floor) {
this._y = floor;
yspeed *= -0.6;
if (yspeed<=-19) {
jumping = false;
}
}
}
}
// change modes
on (keyPress "<Down>") {
if (Mode == "standing") {
Mode = "rolling";
} else {
Mode = "standing";
}
}