ForumsProgramming ForumJumping and ground help plz

8 3645
staticzone
offline
staticzone
67 posts
Nomad

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;
}
}

onClipEvent (enterFrame) {
this._y += 5;
if (_root.ground.hitTest(this._x, this._y, true)) {
this._y -= 5;
}
}
onClipEvent (enterFrame) {
if (this.hitTest(_root.rope1)) {
_root.realrope1.gotoAndPlay(2);
}
}
onClipEvent (enterFrame) {
if (this.hitTest(_root.rope2)) {
_root.realrope2.gotoAndPlay(2);
}
}
onClipEvent (enterFrame) {
if (this.hitTest(_root.enddoor)) {
_root.enddoor.gotoAndPlay(2);
_root.hero._x = 3000;
}
}
onClipEvent(enterFrame) {
if(_root.lives<=0)
_root.gotoAndPlay(1);
}
onClipEvent(enterFrame) {
if(_root.hero_hp<=0) {
_root.hero.gotoAndStop(10);
}
}
onClipEvent (keyUp) {
gotoAndPlay(1);}





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.

Thanks

  • 8 Replies
staticzone
offline
staticzone
67 posts
Nomad

Anybody?

Darkroot
offline
Darkroot
2,763 posts
Peasant

Can we have a picture of the problem? Kinda hard to judge problem with a gaint wall of as2 code.

nixon
offline
nixon
11 posts
Nomad

My personal preference is to use the coordinates instead of hittests. That could solve your problem.

alsage
offline
alsage
132 posts
Nomad

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:
http://tlunitedpicturesforsite.webs.com/example.png

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

{hopefully this will work XD}

alsage
offline
alsage
132 posts
Nomad

It is also good to comment your code... some people will get confused about all that

and another add on doing hittests is really hard for your computer to manage you can try to make an array which is always good =D

PixelSmash
offline
PixelSmash
566 posts
Nomad

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.

Good luck!

markzi
offline
markzi
103 posts
Nomad

u wanna meet barnabey?

staticzone
offline
staticzone
67 posts
Nomad

Well, I fixed it finally. I had to move the ground up higher to make it more stable. Thanks for help though.

Showing 1-8 of 8