Hey guys I was wondering if someone could help me with this problem I'm having. I'm making this temple game, and for some reason every time the guy jumps, he lands he bounces a little and sets in the ground a bit. It just doesn't seem stable at all.
Heres my code for the hero
onClipEvent (load) { power = 3; radius = 6; _x = 497; _y = 374; } onClipEvent (enterFrame) { if (Key.isDown(Key.LEFT)) { _x -= power; gotoAndStop(3); } if (Key.isDown(Key.RIGHT)) { _x += power; gotoAndStop(2); } while (_root.wall.hitTest(_x, _y+radius, true)) { _y--; } while (_root.wall.hitTest(_x, _y-radius, true)) { _y++; } while (_root.wall.hitTest(_x-radius, _y, true)) { _x++; } while (_root.wall.hitTest(_x+radius, _y, true)) { _x--; } while (_root.door1.hitTest(_x, _y+radius, true)) { _y--; } while (_root.door1.hitTest(_x, _y-radius, true)) { _y++; } while (_root.door1.hitTest(_x-radius, _y, true)) { _x++; } while (_root.door1.hitTest(_x+radius, _y, true)) { _x--; } while (_root.door2.hitTest(_x, _y+radius, true)) { _y--; } while (_root.door2.hitTest(_x, _y-radius, true)) { _y++; } while (_root.door2.hitTest(_x-radius, _y, true)) { _x++; } while (_root.door2.hitTest(_x+radius, _y, true)) { _x--; } } onClipEvent (enterFrame) { if (Key.isDown(Key.SPACE) && !jumping) { vel_y = 20; jumping = true; gotoAndStop(4); } if (jumping == true) { vel_y -= 1; if (vel_y<=-10) { vel_y = -10; } this._y -= vel_y; } if (Key.isDown(Key.RIGHT) && jumping == true) { gotoAndStop(5); } if (Key.isDown(Key.LEFT) && jumping == true) { gotoAndStop(4); } if (_root.ground.hitTest(this._x, this._y, true)) { vel_y = 0; jumping = false; } }
I have the walls which is everything and just the tops of everything for the ground I also have to make the walls real thick on the bottom so that when he jumps he hits his head on the ceiling. Im not sure what's going on, I want things to be smooth but their not.
ok so you I am sure you know what a pointer is... that + that indicates {0,0} in flash... well go to your player movieclip inside your library... check to see where your pointer is located if its directly in the middle of your object than it needs to be positioned at the bottom.
Like This:
there is a problem to this method tho... if you plan on adding walls or stairs it will go halfway like before.. but it is a quick solution
What probably happens is that when your character is on it's way down, the distance between it and the ground is less than the (negative) vel_y value. It doesn't detect this however, since the hittest comes out negative. On the next frame, the value is substracted, and the player is placed into the ground. The hittest returns true, and as far as the code is concerned, it's done.
So what you want to do is check if the distance is less than the vel_y, and if it is, set the vel_y to that distance - otherwise leave it as it is.