//(if you take out the stuff talking about jump and gravity the left and right move fine.) anyone who can help i would appreciate it. and also tell me what you did.
Well, it's a pretty messy solution in my opinion. Also, I don't get the point of those returns. If you delete those leftisdown and rightisdown functions, it would be better. Just write If ( Key.isDown(Key.LEFT)) { Â Â Â Â Char.gotoAndStop(2); Â Â Â Â Char.accel -= 1; Â Â Â Â Char._xscale = -100; }
IMO you should make some booleans which go true if key is pressed and false on key up. also keep a boolean for hitTest with ground that way you dont have to calculate it every time. I dunno how you are trying to jump here is some code that might help
jumpInter = setInterval(jumpAction, 40); } public function jumpAction() { char.y += 20; if (char.y >= 110) { char.y = 110; clearInterval(jumpInter); jumpInter = setInterval(stopJump, 40); } } public function stopJump() { char.y -= 20; if (char.y <= -50) { char.y = -50; clearInterval(jumpInter); jumpInter = -1; } }
In here I set a setInterval to jump up and then I come down. you can use your gravity thing with this and in stop jump you can check hitTest with ground to stop the character going down. Hope this helps.
That's as3, googly :S And however, I think that will be like all way up, hitting something invisible and all way down. If you want a more realistic effect you should write if (Key.isDown(Key.UP)) { jumping = true } if (jumping == true) { char._y -= jumpspeed jumpspeed -= 1 } if (!Char.ground.hitTest( _x,_y, true)) { jumping = false jumpspeed = the starting value } so, when jumpspeed become 0 the character will stop in the air for a moment, then jumpspeed will become a negative value and the character will start falling
hey gabo... I meant to give the logic only, I never said will give the code in as2... its just logic.... if you didnt read my post let me say again "IMO you should make some booleans which go true if key is pressed and false on key up. also keep a boolean for hitTest with ground that way you dont have to calculate it every time." which is what u have done.... I was just giving a substitute code...