Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (7th_zorro), 927 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
random jump strength #412826
12/03/12 20:31
12/03/12 20:31
Joined: Dec 2009
Posts: 82
D
Denn15 Offline OP
Junior Member
Denn15  Offline OP
Junior Member
D

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:

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);
        }
}


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 Offline

X
rayp  Offline

X

Joined: Jul 2008
Posts: 2,107
Germany
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;


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] #412833
12/03/12 22:06
12/03/12 22:06
Joined: Dec 2009
Posts: 82
D
Denn15 Offline OP
Junior Member
Denn15  Offline OP
Junior Member
D

Joined: Dec 2009
Posts: 82
thanks for the response. i tried to add your changes but it doesnt change anything

Re: rnadom jump strength [Re: Denn15] #412835
12/03/12 22:19
12/03/12 22:19
Joined: Jul 2008
Posts: 2,107
Germany
rayp Offline

X
rayp  Offline

X

Joined: Jul 2008
Posts: 2,107
Germany
Edit:
@Uhrwerk : Ure right, post removed.

Last edited by rayp; 12/03/12 22:24.

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 Offline
Expert
Uhrwerk  Offline
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: Uhrwerk] #412838
12/03/12 22:26
12/03/12 22:26
Joined: Jul 2008
Posts: 2,107
Germany
rayp Offline

X
rayp  Offline

X

Joined: Jul 2008
Posts: 2,107
Germany
Code:
pXent_addforceglobal
pXent_addforcelocal

Maybe look into.

Last edited by rayp; 12/03/12 22:27.

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] #412853
12/04/12 09:18
12/04/12 09:18
Joined: Dec 2009
Posts: 82
D
Denn15 Offline OP
Junior Member
Denn15  Offline OP
Junior Member
D

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 grin and then the redux function wasnt needed anymore so now the code is shorter too.

thanks for the help


Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1