1 registered members (7th_zorro),
927
guests, and 0
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
random jump strength
#412826
12/03/12 20:31
12/03/12 20:31
|
Joined: Dec 2009
Posts: 82
Denn15
OP
Junior Member
|
OP
Junior Member
Joined: Dec 2009
Posts: 82
|
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:
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);
}
}
Last edited by Denn15; 12/03/12 21:58.
|
|
|
Re: rnadom jump strength
[Re: Denn15]
#412830
12/03/12 21:46
12/03/12 21:46
|
Joined: Jul 2008
Posts: 2,107 Germany
rayp
X
|
X
Joined: Jul 2008
Posts: 2,107
Germany
|
If u hold space ure ball jumps skyhigh. You could do this fex
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);
}
}
}
}
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
my_height = c_trace....
if (my_height <= 0) Iam_On_Floor;
Last edited by rayp; 12/03/12 22:03.
Acknex umgibt uns...zwischen Dir, mir, dem Stein dort... "Hey Griswold ... where u gonna put a tree that big ?" 1998 i married my loved wife ... Sheeva from Mortal Kombat, not Evil-Lyn as might have been expected rayp.flags |= UNTOUCHABLE;
|
|
|
Re: rnadom jump strength
[Re: rayp]
#412836
12/03/12 22:21
12/03/12 22:21
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
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.
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: rnadom jump strength
[Re: rayp]
#412853
12/04/12 09:18
12/04/12 09:18
|
Joined: Dec 2009
Posts: 82
Denn15
OP
Junior Member
|
OP
Junior Member
Joined: Dec 2009
Posts: 82
|
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 and then the redux function wasnt needed anymore so now the code is shorter too. thanks for the help
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|