Darkboy wrote:I think the collision finish event is the best way...
not if you have more than 1 ground actor or you have a certain types of reactions to the collision.

Darkboy wrote:I think this is the correct code :
if(yvelocity<=-3)canjump=0;
I think that code will work if that actor has more than "-3" of yvelocity in that keydown event...
that would only disable jumping while the player is going up,
not while the player is moving down(unless he is falling from a jump.)
- Code: Select all
if(yvelocity > 3)canjump = 0;
is the right one.

here is the draw actor event of my player for my current project(what I have so far.)
- Code: Select all
directional_velocity = 0;
if(pause == 0)
{
char*key=GetKeyState();
int spd = 4;
yrate += gravity;
if(yrate > gravity * 3)j = 1;
if(key[KEY_LEFT] == 1 && key[KEY_RIGHT] == 0)
{
dir = 0;
if(sw == 1 && sj == 0)
{
if(j == 0)x -= spd;
if(j == 1 && xrate > -spd)xrate -= spd / 4;
if(af == 1)
{
if(j == 0)ChangeAnimation("Event Actor", "HRL", FORWARD);
af = 0;
}
}
}
if(key[KEY_LEFT] == 0 && key[KEY_RIGHT] == 1)
{
dir = 1;
if(sw == 1 && sj == 0)
{
if(j == 0)x += spd;
if(j == 1 && xrate < spd)xrate += spd / 4;
if(af == 1)
{
if(j == 0)ChangeAnimation("Event Actor", "HRR", FORWARD);
af = 0;
}
}
}
if(j == 1 && key[KEY_LEFT] == 0 && key[KEY_RIGHT] == 0)
{
if(xrate < -.5)xrate += 0.5;
if(xrate > .5)xrate -= 0.5;
}
if(j == 1 && key[KEY_LEFT] == 1 && key[KEY_RIGHT] == 1)
{
if(xrate < -.5)xrate += 0.5;
if(xrate > .5)xrate -= 0.5;
}
if(sj == 0)
{
if(key[KEY_LEFT] == 0 && key[KEY_RIGHT] == 0 && j == 0)
{
if(af == 1)
{
af = 0;
if(dir == 0)ChangeAnimation("Event Actor", "HSL1", FORWARD);
if(dir == 1)ChangeAnimation("Event Actor", "HSR1", FORWARD);
sw = 0;
}
}
if(key[KEY_LEFT] == 1 && key[KEY_RIGHT] == 1 && j == 0)
{
if(af == 1)
{
af = 0;
if(dir == 0)ChangeAnimation("Event Actor", "HSL1", FORWARD);
if(dir == 1)ChangeAnimation("Event Actor", "HSR1", FORWARD);
sw = 0;
}
}
}
if(key[KEY_UP] == 1 && j == 0 && sj == 0)
{
ChangeAnimation("Event Actor", "HareJump", FORWARD);
sj = 1;
}
if(j == 1 && sj == 0)
{
if(xrate < -2)
{
af = 1;
sw = 1;
ChangeAnimation("Event Actor", "HareJL", FORWARD);
}
if(xrate > 2)
{
af = 1;
sw = 1;
ChangeAnimation("Event Actor", "HareJR", FORWARD);
}
if(xrate >= -2 && xrate <= 2)
{
if(yrate < 0)ChangeAnimation("Event Actor", "HareUp", FORWARD);
if(yrate >= 0)ChangeAnimation("Event Actor", "HareDown", FORWARD);
af = 1;
sw = 1;
}
}
y += yrate;
if(j == 0)xrate = 0;
x += xrate;
}
I use xrate and yrate(real/float, actor varaibles) to work the same as xvelocity and yvelocity.
why: its alot better for pausing your game, you just have to add a few events that decrease your yrate to 0 when you collide with the ground
