The Armor Games website will be down for maintenance on Monday 10/7/2024
starting at 10:00 AM Pacific time. We apologize for the inconvenience.
The Armor Games website will be down for maintenance on Monday 10/7/2024
starting at 10:00 AM Pacific time. We apologize for the inconvenience.
10 | 4434 |
So, I can crouch, but when I try to jump without moving it doesnt but I can crouch and stand still. But when I move and press crouch I still crouch. How do I make it so I don't crouch when I move. Also when I move and press jump it jumps which is fine. Here is the code, It is in AS2:
In walking:
onEnterFrame = function() {
if (Key.isDown(Key.RIGHT) && !Key.isDown(Key.LEFT) && speed < maxSpeed) { speed += accel }
if (Key.isDown(Key.LEFT) && !Key.isDown(Key.RIGHT) && speed > -maxSpeed) { speed -= accel }
if (speed > 0) { _xscale = 100 }
if (speed < 0) { _xscale = -100 }
if ( (!Key.isDown(Key.LEFT) && !Key.isDown(Key.RIGHT) ) || (Key.isDown(Key.LEFT) && Key.isDown(Key.RIGHT) ) ) {
if (Math.abs(speed) < accel ) {
speed = 0
} else {
speed -= speed/Math.abs(speed) * accel
}
}
_x += speed
if (!Key.isDown(Key.UP) ) { jumpIsDown = false }
if (Key.isDown(Key.UP) && !jumpIsDown) {
jumpIsDown = true
gravity = -jumpheight;
gotoAndStop("jump"
} else if (!_root.ground.hitTest(_x + speed, _y + gravity, true) ) {
gravity == 0
gotoAndStop("jump"
} else if (speed == 0) {
gotoAndStop("idle"
}
if (Key.isDown(Key.DOWN)) {
gravity = 0
gotoAndStop("crouch"
}else if (speed == 0) {
gotoAndStop("idle"
}
onEnterFrame = function() {
if (Key.isDown(Key.RIGHT) && !Key.isDown(Key.LEFT) ) { speed += accel; _xscale = 100 }
if (Key.isDown(Key.LEFT) && !Key.isDown(Key.RIGHT) ) { speed -= accel; _xscale = -100 }
_x += speed
if (!Key.isDown(Key.UP) ) { jumpIsDown = false }
if (Key.isDown(Key.UP) && !jumpIsDown) {
jumpIsDown = true
gravity = -jumpheight;
gotoAndStop("jump"
} else if (!_root.ground.hitTest(_x + speed, _y + gravity, true) ) {
gravity = 0
gotoAndStop("jump"
} else if (speed != 0) {
gotoAndStop("walk"
}
if (Key.isDown(Key.DOWN)) {
gravity = 0
gotoAndStop("crouch"
}else if (speed == 0) {
gotoAndStop("idle"
}
}
stop();
onEnterFrame = function() {
if (Key.isDown(Key.RIGHT) && !Key.isDown(Key.LEFT) && speed < maxSpeed) { speed += accel/2 }
if (Key.isDown(Key.LEFT) && !Key.isDown(Key.RIGHT) && speed > -maxSpeed) { speed -= accel/2 }
_x += speed
if (_root.ground.hitTest(_x + speed, _y + gravity, true)) {
while (!_root.ground.hitTest(_x, _y, true)) {
_y++
}
gravity = 0
if (Math.abs(speed) < accel ) { speed = 0; gotoAndStop("idle" } else { gotoAndStop("walk" }
} else {
gravity ++;
_y += gravity;
if (_y > 1000) { gravity == 0; speed = 0; _y = 200; _x = 200 }
}
}
if (Key.isDown(Key.DOWN)) {
gravity = 0
gotoAndStop("crouch"
}else if (speed == 0) {
gotoAndStop("idle"
}
Try pulling the code out of the frames and putting it on the characters movie clip. Use onClipEvent(load) for initiating variables and onClipEvent(enterFrame) for everything else. So instead of gotoAndStop, use this.gotoAndStop.
Once you do that, you will have a good starting point for debugging your game.
Thanks, but is there anyway you can help me with the code i already have?
It seems to me It's most likely a variable thing. I'll look at it when I have more time :P
o.O man how much you worked for this
Wait, are there any compiler errors? If so, what are they? I think I might have found the problem...
No, no errors. And this code sadly took me a few days to figure out. No thanks to that dam crouch code.
Have you followed my initial consideration? Without doing that it won't be easy to debug because your code is all over the place.
You must be logged in to post a reply!