View Full Version : Jumping and structure help
akahan
July 19th, 2005, 09:00 AM
Im making a copy off of a mario game and i need help making my character jump. Can anyone lead me in the direction for code or does anyone have a tutorial? Also, how can i make it so if the character runs into some structure, he cant just go right passed it? Thanks for the help
Enix591
July 19th, 2005, 10:10 AM
Check this out, its a little imperfect but you should get the general idea.
akahan
July 19th, 2005, 10:32 AM
Check this out, its a little imperfect but you should get the general idea.
Thanks man. Ill post questions if i have any.
akahan
July 19th, 2005, 10:42 AM
Okay, but now, my guys, he ends up on with half his body off the screen and half off. Any ideas why?
Blackspirit
July 19th, 2005, 10:54 AM
Well, thats probably because the hittest doesn't take into account the heros current speed. It should calculate if he hits something the frame before he actually hits it.
akahan
July 19th, 2005, 10:58 AM
Okay, so i figured that out, but now, i inserted some code and now he doesnt jump, i hit the space bar, he jumps, but stays up, here is the code i have used so far
onClipEvent (load) {
// gravity is what I called g in the tutorial. The
// higher g the harder the ball will fall.
// gravity = 0 can be set, as an experiment, but
// it will in fact create a "zero gravity" effect
// gravity < 0 will create an inverted gravity effect
gravity = 2 ;
// We set the speed of the ball when it is released.
speedx = 0 ;
speedy = 0 ;
}
onClipEvent (enterFrame) {
this._y-=_root.gravity
if (_root.jumping == "yes") {
_root.gravity -=.5
}
// We calculate the increase of speed
// speedx doesn't change
if(_root.fall==true){
speedy = speedy + gravity ;
// We move the ball.
// speed/5 just makes the motion slower
this._x += speedx/5 ;
this._y += speedy/5 ;
}}
onClipEvent (load) {
Jump = false;
Jumpable = true;
JumpCount = 0;
Gravity = 0;
}
onClipEvent (enterFrame) {
_y += Gravity;
//If you havent hit the bottom of the block//
if (_root.ball.hitTest(_x, _y, true)) {
Jumping = false;
Jump = false;
Gravity = 0;
} else {
if (Gravity<16) {
Gravity += 1;
} else {
Gravity = 16;
}
}
if (Key.isDown(Key.RIGHT)) {
if (not (_root.grounds.hitTest(_x+(_width/2), _y-(_height/2), true))) {
_x += 4;
}
}
if (Key.isDown(Key.LEFT)) {
if (not (_root.grounds.hitTest(_x-(_width/2), _y-(_height/2), true))) {
_x -= 4;
}
}
if (Key.isDown(Key.SPACE)) {
if (Jump == false && Jumping == false) {
Jump = true;
Jumping = true;
}
if (Jump) {
Jumping = true;
}
} else {
Jump = false;
}
if (Jumping == true) {
_y -= 8;
}
}
akahan
July 19th, 2005, 11:04 AM
onClipEvent(enterFrame){
if (this.hitTest(_root.ball)){
_root.fall=false;
_root.Jumping="no"
}}
//This statement looks to see if character is touching the objects
thats the code i used on the block he is supposed to be standing on
akahan
July 19th, 2005, 12:45 PM
anyone got any ideas, cuz when i turn gravity on i fall through the floor
Blackspirit
July 20th, 2005, 01:22 AM
The post three posts up, #6. Please don't tell me you put all that code onto one movieclip. 2 onLoads and 2 onenterframes on one clip can really make your code do wierd things.
What were you hoping the code you inserted to do?
akahan
July 20th, 2005, 08:50 AM
I was hoping that it would make my guy jump, and not fall through the bottom. But instead, when i jump, he just freezes in the air.
edit: im pretty sure those were not into one movieclip
Blackspirit
July 20th, 2005, 09:01 AM
Fall through the bottom? you mean drop down the bottom of the screen?
akahan
July 20th, 2005, 09:05 AM
Yeah, he falls out of the sight area, and does not land onto my log thingy that i ahve set there
Blackspirit
July 20th, 2005, 09:06 AM
And this log thingy, it is in the same movieclip as the ground movieclip?
akahan
July 20th, 2005, 09:09 AM
yeah, thats what im talking about.
btw, thanks for the replies
Blackspirit
July 20th, 2005, 09:12 AM
hmm, thats wierd. Anything in the ground movieclip it should be detecting the hit.
Can you post the fla with your changes? Its easier to debug that way.
akahan
July 20th, 2005, 09:16 AM
Okay, i have totally new code, but if you want me to insert the old code into the .fla, just let me know
*i just tried to open it and it said that the .fla was too lard in the manage attachments so waht should i do?
akahan
July 20th, 2005, 09:17 AM
got it neveremind
edit: the game is on frame three of the layer, im at a camp and were supposed to make a site with it
Blackspirit
July 20th, 2005, 09:19 AM
try to get the fla size down. It has to be less then 85kb or something. Save a backup, and then get rid of any graphics that are huge.
Or upload it to a website :)
EDIT:Cool, I just take a look and try to fix it up.
Blackspirit
July 20th, 2005, 09:29 AM
ok, in your "grounds" movieclip your starting the ground() function. But you've called it "grounds" :)
So change the name of your function to ground()
akahan
July 20th, 2005, 09:30 AM
Okay, so i just ran that, and now half of his body is above the ground, and half is under, lol.
Blackspirit
July 20th, 2005, 09:31 AM
Just comment out the "ball._y -= (ball._y-Position);" in your ground() function.
akahan
July 20th, 2005, 09:37 AM
Okay, Thank you very much for all of the replies but i have one final question. How do i make him ahve to jump over some objects, cuz he just runs over some of them.
Also, where in the code do i make him jump higher.
Sorry for the all the questions.
Thanks!!
edit, i got him jumping okay, thanks for the help
Blackspirit
July 20th, 2005, 09:54 AM
Well, you can change the jump height with the _root.Gravity += 10; in the code for the space key. Just change it to 20 :)
The hit detection is the hardest part.
Take the code out of the grounds movieclip.....and put this in the movieclip that contains most of your code, just under where it says onClipEvent(enterFrame)
if (_root.ball.hitTest(_root.grounds)) {
_root.Position = this._y
_root.ground()
}
else if(_root.ball.hitTest(_root.brick)) {
_root.Position = this._y
_root.ground()
}
else
{
_root.Falling = "yes";
}
The if statement is checking for collision with the grounds movieclip, while the second else if is checking with the bricks. We put a final else if its not colliding with anything.
The collision detection isn't the best, but I think it'll do for jumping on things.
To add more, just put more else if statments into it, with the other things you want to collide with....easy :D
akahan
July 20th, 2005, 10:01 AM
Alright, thanks for the post. Sorry to be a pain, but now when i jump into the brick or no totally on top of it, my guy doesnt fall down, he kinda like goes in to the brick and has like half of his body under the brick and his head up over the brick. Any ideas why?
Blackspirit
July 20th, 2005, 10:06 AM
lol, yeah, thats the problem with this basic hit detection. It won't take into accounts for things like that.
What you'll need to do is check if the brick._y is higher then the ball._y, if it is higher, that means your under it, so you'll need to say Falling = "no".
But I'm off to bed. Try to get the pipe and the mushroom to be detected when hit. :)
akahan
July 20th, 2005, 10:11 AM
Okay, thanks for all your help. It was much appreciated.
akahan
July 21st, 2005, 10:39 AM
Alright, so new question now, i have the hittesting working fine except one thing, they can walk through the sides of hte objects, but they cna stand on them fine, how do i prevent them from walking through the objects? Also, how to i configure continuous movement of an enemy?
If you need the new code, let me know.
Thanks for the help.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.