Welcome Guest [Log In] [Register]
Welcome to Brackenwood. We hope you enjoy your visit.


You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Character Jump; how?
Topic Started: Feb 27 2006, 03:54 AM (339 Views)
boundless
Member Avatar
stuck in the third dimension
I'm working on a game for the ArmorGames comp and I'm using fbf animation. If I wanted to make the character jump, would I animate him jumping and then move him with actionsctipt? I need it for jumping from one ledge to another, jumping over objects, jumping onto other places, etc.

My character movie clip is called box_mc and I go to the different animations (walking, crouching, etc.) by jumping to the frame. So the jumping animation would be gotoAndStop(4). I can't figure out gravity or how I would make him fall back if he jumped into a wall. Thanks.

By the way, I use Flash MX (not 2004).



EDIT: I found some code that helped me assign a MC as the ground and now the character has gravity and the ability to jump. My problem is that he can jump, but I want the power of the jump to depend on how long you hold the UP key. I also need other objects to block the character and have him jump on them. Right now I have a box that stops my character from going further, but if I jump on it, he falls into it and can't move unless you jump back out of it.

And I still need better code for the jump... I don't like it the way I have it now.
Offline Profile Quote Post Goto Top
 
smoscar_01
Member Avatar
Mid-Level ActionScripter
you really need to have gravity on mind cos not only your character can fall down, also enemies, items or anything, gravity is needed at a scrolling game

Code:
 
if (Key.isDown(Key.UP) && jumping != true) {
//the jumping needs to be false cos you dont want your
//character to jump from thin air
  jumping = true;
}
if (jumping==true) {
 this.gotoAndStop("jump"); //if you want to draw a jumping sprite
 this._y -= jump;
 jump -= .5;
 if (jump<0) {
   falling = true;
 }
 if (jump<-15) {
   jump = -15;
 }
}


now youll need something that stops your movement, lets say you have a movie clip caled ground

Code:
 
if (jump<-15) {
 jump = -15;
}
if (_root.ground.hitTest(this._x, this._y, true) && falling) {
 jump = 12;
 jumping = false;
 falling = false;
}


that would do the trick :lol:
Offline Profile Quote Post Goto Top
 
boundless
Member Avatar
stuck in the third dimension
Did you read my post?
Quote:
 
I found some code that helped me assign a MC as the ground and now the character has gravity and the ability to jump.


I have the gravity and the ground, I just need a way of jumping that depends on the length of time you press the UP key. So if you just tap it you do a small hop and if you hold it for a second, you jump several feet.

The other thing is that I need objects to block your path. One of the objects stops the character completely and you cant just jump on it. The other object is there but all you have to do is walk into it to get up it.

So if you dont understand that, here's basically what I need:

  • The character's jump depends on the length of time the UP key is pressed.
  • Objects that block your path, unless you jump onto them.
Offline Profile Quote Post Goto Top
 
Mr. Jiggmin
Member Avatar
made of tulips
Did YOU read your post?
Quote:
 
And I still need better code for the jump... I don't like it the way I have it now.


I added a couple of lines to smoscar's code that should make them jump higher when you hold down the jump key.

Code:
 
if (Key.isDown(Key.UP) && jumping != true) {
//the jumping needs to be false cos you dont want your
//character to jump from thin air
jumping = true;
holdingKey = true;
}
if (jumping == true) {
this.gotoAndStop("jump");
//if you want to draw a jumping sprite
this._y -= jump;
jump -= .5;
if (jump<0) {
 falling = true;
}
if (jump<-15) {
 jump = -15;
}
//if you keep holding the key, you jump higher  
if (holdingKey == true) {
 jump += .3;
}
if (!Key.isDown(Key.UP) && holdingKey == true) {
 holdingKey = false;
}
}
if (_root.ground.hitTest(this._x, this._y, true) && falling) {
jump = 12;
jumping = false;
falling = false;
}


Hope that helps ya. :)
Offline Profile Quote Post Goto Top
 
boundless
Member Avatar
stuck in the third dimension
Mr. Jiggmin
Feb 27 2006, 01:05 PM
Did YOU read your post?

Uh yeah I said I needed a more advanced jump, not more code for the jump I already have. I'm going to try your code now and edit the post with results... so thanks in advance for helping out. And thanks to smoscar for doing what he could. I should have said thanks anyway cause I guess I was being rude. So thank you both for going out of your way and typing up some code to help me out. :D

EDIT: Hmm well it works, but it moves pretty slow and a little too high. I'll play around with the numbers, but I think I may have an idea for a different method to this whole jump thing.
Offline Profile Quote Post Goto Top
 
smoscar_01
Member Avatar
Mid-Level ActionScripter
Quote:
 
So if you dont understand that, here's basically what I need:


:o Sorry if I tried to help you it wont happen again :angry:

ooh and yeah I read it when it wasnt edited
Offline Profile Quote Post Goto Top
 
boundless
Member Avatar
stuck in the third dimension
I acknowledged the fact I was rude and then I thanked you and Mr. Jiggmin for helping me out. You want me to send you flowers or something?


Anyway, I've got a whole different way of doing it now but thanks for the code guys.
Offline Profile Quote Post Goto Top
 
smoscar_01
Member Avatar
Mid-Level ActionScripter
yeah the flowers would be nice <_< lol :lol:
Offline Profile Quote Post Goto Top
 
Mr. Jiggmin
Member Avatar
made of tulips
Out of curiosity, how are you doing it now?
Offline Profile Quote Post Goto Top
 
boundless
Member Avatar
stuck in the third dimension
I'm getting the jump button to start an animation for the jump and if you hold down the key all the way through, he jumps further than if you let go early. I'm working on it and I still have a lot of problems with multiple keys. I wish I could get Left + Down to make the character do a low walk and other stuff.

EDIT: I got the jump working!! It's more realistic and works well for the game I'm doing. Woo I feel good cause I can spend more time on other aspects of the game now :D
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Actionscript · Next Topic »
Add Reply