Page 1 of 1

Help! Jump problem!

PostPosted: Tue Jan 29, 2008 1:24 pm
by crazypotato
We're having trouble with one of our characters. He will keep jumping if you want him to and practically fly! Plz help!!!!!!!!!!!!!!!!!! :( :( :( :( :( :( :( T Y SO MUCH.

Re: Help! Jump problem!

PostPosted: Tue Jan 29, 2008 3:39 pm
by Kalladdolf
help!!!!!!!!!!!!!! panic!!!!!!!!!!!!!!! kidding :wink:
so he will just jump from the air?
ok, first disable the repeat event when you press the button (if you haven't done so yet)
then use if-conditions. it's easy:
character -> collision on top side of platform -> script editor
Code: Select all
canjump = 1; //canjump is a variable that you'll make yourself

and then when you press the "jump" button:
Code: Select all
if(canjump == 1)
{*your jump action*;
canjump = 0;}


so this basically means: he will jump if he has stood on the ground before and when he's jumped, he will disable that.
if he touches the ground again, he'll again be able to jump.
hope that helped...
:D

Re: Help! Jump problem!

PostPosted: Tue Feb 12, 2008 9:13 am
by Bee-Ant
To make double jump
Player>Collision>Top side of platform
Code: Select all
canjump=2;

Player>Keydown>JumpKey
Code: Select all
if(canjump>0)
{
    yvelocity-=10;
    canjump--;
}

Re: Help! Jump problem!

PostPosted: Tue Feb 12, 2008 10:07 am
by edh
There is a really weird effect from code like that, Bee-Ant.

When you land on a platform, and then fall off of it, you can jump twice in mid air.

Does anyone have a work around for that?

Re: Help! Jump problem!

PostPosted: Tue Feb 12, 2008 10:22 am
by Bee-Ant
Ah...so simple...
Player>CollisionFinish>Platform
Code: Select all
canjump=0;

Now...the "weird effect" fixed :D

Re: Help! Jump problem!

PostPosted: Tue Feb 12, 2008 10:48 am
by edh
But doesn't that create a race condition with the two events on the platform? You have a collision with the platform so you can jump, when that event is over, you can't jump. So while you are on the platform, you will notice that sometimes the jump button doesn't work.

So, if you have
  • collision, top of platform, repeated where jump = yes
  • collision finish, top of platform, not repeated where jump = no

you will get something like the behavior in this example... (Bee-Ant you may recognize it :) )

When I run this, if I'm on a platform and I press space bar to jump, it intermittently works. Do you see the same thing?

Re: Help! Jump problem!

PostPosted: Tue Feb 12, 2008 11:22 am
by DilloDude
The reason for this is that physical response stops the collision. So you're just next to the platform, not actually colliding (intersecting) with it. So the collisionFinish event is triggered, making canjump flicker between 1 and 0. One good method I have for solving this is to use a variable counter (for this example we'll call it time). On your collision with the top of platform, set time to 0. Rather than using a collisionFinish event, put this in drawActor somewhere around the gravity section:
Code: Select all
time ++;
if (time > 2)//adjust this variable to suit
{
    canjump = 0;
}

You need to adjust the variable relative to your gravity amount. The lower it is, the sooner you can't jump after leaving the platform, but the greater the chance of not being able to jump even on the platform sometimes. Play around with this and adjust to suit.

Re: Help! Jump problem!

PostPosted: Tue Feb 12, 2008 11:26 am
by Bee-Ant
Let me see :roll:

Re: Help! Jump problem!

PostPosted: Fri Feb 15, 2008 10:45 am
by edh
...

Re: Help! Jump problem!

PostPosted: Sat Feb 16, 2008 1:50 am
by Bee-Ant
Whoa...this not what I want...

Re: Help! Jump problem!

PostPosted: Thu Feb 21, 2008 1:58 pm
by Kalladdolf
the code DilloDude gave is really cool! It solves something I've been having loadsa trouble about. Thanks. :)
Also, just crossed my mind... you could make a child actor (invisible) relative to the player and make it have a position a little below the player.
It won't have the physical response with the plattform, but it will decide whether to enable or disable canjump (even including the collision finish event!!!)

now, did you get that? should I post a demo? :roll:

Re: Help! Jump problem!

PostPosted: Thu Feb 21, 2008 2:20 pm
by Bee-Ant
Whatever you do...I'm still confused anyway :P

Re: Help! Jump problem!

PostPosted: Thu Feb 21, 2008 5:39 pm
by Kalladdolf
lulz, actually it's quite simple, but I sometimes get con-fuzzled just as well :lol: