Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
0 registered members (), 1,012 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Physics Jump #341503
09/17/10 15:35
09/17/10 15:35
Joined: Sep 2010
Posts: 2
J
jpvanoosten Offline OP
Guest
jpvanoosten  Offline OP
Guest
J

Joined: Sep 2010
Posts: 2
I was working through the Lite-C workshop tutorials and I got to workshop 19: Physics

I guess the tutorials were written for A7 because they it didn't work at first, but I got that part sorted out pretty quickly when I found the docs about the pX_ methods.

I wanted to extend the marble game a little bit by adding a jumping feature. The idea is that if the player presses the space bar, the ball will jump.

Well, I got the jumping part working pretty quickly, but I want to make sure the user can only jump if the ball is actually touching the ground (no jumping forever in midair).

I can't figure out how to detect if the ball is at rest on the ground.

Can anybody tell me how I can tell if the ball entity is on the ground or if it is in "free-fall"?

Thanks in advance.

Here is the script file so far (slightly edited version of Lite-C workshop 19: Physics
Code:
///////////////////////////////////////////////////////////////
// ODE version of script19
// Only for use with A7

#include <acknex.h>
#include <default.c>
#include <ackphysX.h>

///////////////////////////////////////////////////////////////

ENTITY* ball;
VECTOR* hit_distance;

var is_touching;

function EventTrigger()
{
	is_touching = false;
	switch(event_type)
	{
		case (EVENT_FRICTION):
		{
			is_touching = true;
		}	
		break;
	}
	
}

function phys_Controller()
{
	VECTOR torque;
	VECTOR force;
	
	vec_zero(torque);
	vec_zero(force);
	
	pXent_settype (my, PH_RIGID, PH_SPHERE); // set the physics entity type
	pXent_setmass (my, 3); // and its mass
	pXent_setfriction (my, 500); // set the friction
	pXent_setdamping (my, 40, 40); // set the damping
	pXent_setelasticity (my, 50); // set the elasticity
	
//	my.emask |= ENABLE_FRICTION | ENABLE_BLOCK | ENABLE_ENTITY | ENABLE_IMPACT;
	my.event = EventTrigger;
	
	pXent_settriggerflag(my, NX_TRIGGER_ENABLE, 1);
		
	var space_pressed = false;
	is_touching = true;
	
	while (true)
	{		
		torque.x = 150 * time_step * (key_cur - key_cul); // move the ball using the cursor keys
		torque.y = 150 * time_step * (key_cuu - key_cud); // 25 sets the x / y movement speeds
		torque.z = 0; // no need to move on the vertical axis
		force.z = 0;
				
		if ( key_space && !space_pressed && is_touching )
		{
			force.z = 1000;
			space_pressed = true;
			is_touching = false;
		}
		space_pressed = key_space;
		
		pXent_addtorqueglobal (my, torque); // add a torque (an angular force) to the ball
		pXent_addforcecentral (my, force);
		camera.x = my.x - 300; // keep the camera 300 quants behind the ball
		camera.y = my.y; // using the same y with the ball
		camera.z = 1000; // and place it at z = 1000 quants
		camera.tilt = -60; // make it look downwards
		wait (1);
	}
	
}

function main()
{
	physX_open();
	
	level_load("roller.wmb"); // load the level
 	ball = ent_create ("ball.mdl", vector(-400, 0, 100), phys_Controller); // create the ball
 	
	pX_setgravity (vector(0, 0, -9.81)); // set the gravity
}


You'll notice from the code sample, that I tried to set the emask to some events and I set the event property of the entity, but that didn't work... The event never got called.
So I commented that out.
I then tried to use the "pXent_settriggerflag" method, but that turned my entity into a "trigger" object (I guess) and it just falls through the floor... BUT, my EventTrigger method did get called when it hit the floor...

So how can I correctly check if the ball is actually touching the ground? This should be a common feature in most games.

Thanks in advance!

Re: Physics Jump [Re: jpvanoosten] #341517
09/17/10 18:31
09/17/10 18:31
Joined: May 2002
Posts: 7,441
ventilator Offline
Senior Expert
ventilator  Offline
Senior Expert

Joined: May 2002
Posts: 7,441
if you can't get the physics event stuff to work you could also simply use a trace and check if the distance is bigger than the radius + some margin.

Re: Physics Jump [Re: ventilator] #341920
09/21/10 18:17
09/21/10 18:17
Joined: Sep 2010
Posts: 2
J
jpvanoosten Offline OP
Guest
jpvanoosten  Offline OP
Guest
J

Joined: Sep 2010
Posts: 2
Thanks ventilator for your response.

I was hoping for an explanation as to why the events are not working, or better yet, an explanation about how to setup the events correctly to receive the impact and touching messages from the PhysX system (the documentation is really lacking in this respect)

Maybe there is a working example (with source and assets)?

Your suggestion to do a trace to see if there is anything below the ball entity may work. I actually tried to do that already but the value I was getting back from the trace function was always some extremely large number that I couldn't make any sense of (that's why you see the "hit_distance" variable that isn't doing anything anymore :)).

Has anyone successfully implemented a jumping function in there game?


Moderated by  HeelX, Spirit 

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