random jump strength

Posted By: Denn15

random jump strength - 12/03/12 20:31

ive started working on a marble madness type game and i would like the ball that you are controlling to jump and ive managed to make it jump when you press space but sometimes the ball jumps a sky high and other times the ball almost doesnt jump at all. there is probably a better way tro script a jump the way i did, since im completely new to lite-c but anyways these are the lines of code concerning the jumping:

Code:
function jump()
{
	if (event_type == EVENT_FRICTION)
	{
		if (key_space)
		{
			if (!snd_playing(sound))
			{
				ball_jump.z = 60;
				sound = snd_play (impact, 100, 1);
			}
		}
	}
}

function redux()
{
	while (1)
	{
		if (ball_jump.z > 0)
		{
			ball_jump.z = - 1*time_step;
		}
	wait(-0.1);
	}
}


function main()
{
        pXent_setcollisionflag(ball, NULL, NX_NOTIFY_ON_TOUCH);
	ball.event = jump;
	redux();
        
        while (1)
        {
                pXent_addvelcentral(ball, ball_jump);
        }
}

Posted By: rayp

Re: rnadom jump strength - 12/03/12 21:46

If u hold space ure ball jumps skyhigh. You could do this fex
Code:
var jumping = 0;
function jump()
{
	if (event_type == EVENT_FRICTION)
	{
		if (key_space && !jumping)
		{
			if (!snd_playing(sound))
			{
                                jumping = 1;
				ball_jump.z = 60;
				sound = snd_play (impact, 100, 1);
			}
		}
	}
}



Code:
function redux()
{
	while (1)
	{
		if (ball_jump.z > 0)
		{
			ball_jump.z = - 1*time_step;
		}
                else jumping = 0;
	wait(1); // changed from wait(-0.1) = ?
	}
}


See what i mean ? I did not test your script, but i guess you know what i meant with the simple change.

Besides that u should combine your redux function with a c_trace. Simple checking Balls.Z != 0 wont work ( fex on steps ).
ex
Code:
my_height = c_trace....
 if (my_height <= 0) Iam_On_Floor;

Posted By: Denn15

Re: rnadom jump strength - 12/03/12 22:06

thanks for the response. i tried to add your changes but it doesnt change anything
Posted By: rayp

Re: rnadom jump strength - 12/03/12 22:19

Edit:
@Uhrwerk : Ure right, post removed.
Posted By: Uhrwerk

Re: rnadom jump strength - 12/03/12 22:21

That won't help him too much as he is using physX.

Denn15, when implementing a jump you normally apply an upward impulse to an object.
Posted By: rayp

Re: rnadom jump strength - 12/03/12 22:26

Code:
pXent_addforceglobal
pXent_addforcelocal

Maybe look into.
Posted By: Denn15

Re: rnadom jump strength - 12/04/12 09:18

i figured it out.

instead of having the pXent_addvelcentral(ball, ball_jump); in the while loop i added pXent_addvelcentral(ball, vector(0, 0, 300)); to the jump function and now it works like it should grin and then the redux function wasnt needed anymore so now the code is shorter too.

thanks for the help
© 2024 lite-C Forums