PH_CHAR

Posted By: 3run

PH_CHAR - 03/09/12 23:57

I've made movement with PH_CHAR, it works good for me, but I have two question, answers for which I couldn't find myself...

FIRST QUESTION:
Quote:
How do I change BBOX for the PH_CHAR run-time, I want to make crawling, but there is no way to make it as with usual "c_move" as I used to do before, I've seen how painkiller where switching collusion bodies, but that was for PH_RIGID, and it doesn't work for me with PH_CHAR.

SECOND QUESTION:
Quote:
How do I adjust friction parameter for PH_CHAR?
pXent_setfriction(my, 0);
didn't help!

Posted By: Ch40zzC0d3r

Re: PH_CHAR - 03/10/12 08:41

Oh man.
Why you use PhysX for your movement?
Use c_move and c_trace and move a passable physx body with your player.
This also do its job when you want to kick rigid_bodys.
Posted By: 3run

Re: PH_CHAR - 03/10/12 08:44

I don't want to kick rigid bodies, I need proper collusions, without that ellipsoid bullshit, and I've archived them.
All I need to implement is crawling now. Other stuff works smooth and perfect, at least for my needs (fps).
Posted By: painkiller

Re: PH_CHAR - 03/10/12 12:31

Why my solution doesn't work for you? Have two invisible entities, one with the standing BBOX and other one with the crawling BBOX, then enable/disable them from physX depending if player is crawling or not, and attach you player model to them
Posted By: 3run

Re: PH_CHAR - 03/10/12 15:57

Tried, but didn't work.. may be I've done something wrong...
Posted By: 3run

Re: PH_CHAR - 03/16/12 09:17

ANY ONE???

Quote:
How do I adjust friction parameter for PH_CHAR?
pXent_setfriction(my, 0);
didn't help!

Posted By: Wjbender

Re: PH_CHAR - 03/16/12 11:07

Not try to crawl before but when im using phrigid for type and pxent_rotate(ent,null,vector(0,0,90)) it seems possible execpt the animation gonna have to been done vertical
Posted By: 3run

Re: PH_CHAR - 03/16/12 16:10

Problem is with friction thing, how to lower friction for PH_CHAR?
Posted By: 3run

Re: PH_CHAR - 03/17/12 15:25

Any ideas, guys, or should I ask directly in "Ask the Developers" forum?
Posted By: Wjbender

Re: PH_CHAR - 03/17/12 20:25

Not so familiar with gamestudio yet but maby the setmaterial func where you could specify more dynamics would be worth a try ,asuming that setmass or setdamping makes no difference...
Posted By: rojart

Re: PH_CHAR - 03/18/12 20:15

Originally Posted By: 3run
Any ideas, guys, or should I ask directly in "Ask the Developers" forum?

From physX sdk documentation you should read the friction trouble (orange color), maybe it helps.

Quote:
Character Controller

The goal of the character controller SDK is to provide a default built on top of the NVIDIA PhysX SDK. Roughly it has to support the following:

Character control
Character interactions
This covers a very high number of features, which can be implemented in numerous ways. The goal is not to implement all of them (which would be a daunting task), but to offer a default implementation that people can use as a starting point. For example, the character's bounding volume could be anything, from a box to an inverted pyramid; therefore, in our initial implementation we support two common bounding volumes: an AABB and a capsule.

One might wonder why we didn't use the physics engine directly to implement the character controller. Here is the story.

Implementation Decisions
In the past, games didn't use "real" physics engines. However, they still used a character controller to move a player in a level. These games, such as Quake or even Doom, had a dedicated, customized piece of code to implement collision detection and response, which was often the only piece of physics in the whole game. It actually had little physics, but a lot of carefully tweaked values to provide a good feeling while controlling the player. The particular behavior it implemented is often called the " collide and slide" algorithm, and it has been tweaked for more than a decade. The result is that players expect to find the same well-known behavior in new games, and providing them with anything else is often dangerous (a few games come to mind but I’m not sure it’s appropriate to name them). This is especially true if provided behavior is not as robust and stable as before, which is exactly what happens if you use a typical physics engine directly to control players.

In particular, here is a (non-exhaustive) list of typical problems when using a physics engine for character controllers:

(Lack Of) Continuous Collision Detection: Typical physics engines use discrete collision checks, leading to the famous tunneling effect that has plagued various commercial & non-commercial physics packages for years, which leads to three main problems:


The tunneling effect itself - if the character goes too fast, it might tunnel through a wall.
As a consequence, the maximum velocity of the character might be limited (hence also limiting the game-play possibilities).
Even without tunnel, the character might jitter when pushed forward in a corner. For example, the engine keeps moving it back and forth to slightly different positions.


No Direct Control: A rigid body is typically controlled with impulses or forces. It is nearly impossible to move it directly to its final position until you have converted the delta position vector to impulses or forces and applied them in hopes that the character will be where you wanted it to be as a result. Usually it doesn't work very well, in particular when the physics engine uses an imperfect linear solver.


Trouble with Friction: When the character is standing on a ramp, you don't want it to slide. Infinite friction is desired. When the character is moving forward on that same ramp, or sliding against a wall, you don't want it to slow down, thus a null friction is needed. These are usually defined with either 0 or infinite. However, the friction model might not be perfect, and what you actually get is very little friction, so you can still feel the character slowing down, or a high-but-not-infinite friction, so the character slides very slowly on that ramp no matter how artificially high the friction parameters are. The conflicting requirements for ramps mean that usually there is simply no way to perfectly model desired behavior.


Trouble with Restitution: Basically you don't want any restitution, ever. When the character moves fast and collides with a wall, you don't want it to bump against it. When the character falls from a height and lands on the ground, flexing his legs, you definitely don't want any bumps, which would visually look terrible. But once again, even when the restitution is exactly zero, you sometimes get a small bump nonetheless. This is not only related to the non-perfect nature of the linear solver, but also has to do with how typical penetration-depth-based engines recover from overlap situations, sometimes applying too high a force that repels objects more than desired.


Undesired Jumps: It is often important that a character stick to the ground, no matter what the physical behavior should be. For example, characters in action games tend to move fast, at unrealistic speeds. When they reach the top of a ramp, the physics engine often makes them jump a bit, in the same way a fast car would jump in the streets of San Francisco. But that is often not desired: the character should stick to the ground regardless of its current velocity. This is sometimes implemented using fixed joints, which is a terrible, terrible solution to a very simple problem that has been solved for years without requiring all the modern complexity of a physics engine.


Undesired Rotations: Finally, a character is always standing up and never rotating. However, a physics engine often has poor support for that kind of constraint, and a great deal of effort is put into just preventing a capsule around the character from falling (it should always stand up on its tip). This too is sometimes implemented using artificial joints, and the resulting system is neither very robust nor very fast.
In summary, a lot of time is spent in disabling the physics engine's features, one after the other, for the whole purpose of emulating an otherwise simple piece of customized code. This is not the correct approach.

--------------------------------------------------------------------------------

Copyright © 2008 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com

Posted By: 3run

Re: PH_CHAR - 03/18/12 21:25

Hey rojart, thank you for leanding a hand. I've read the article, but isn't it about PH_RIGID? I guess it is, and the prolem I've faced is that player gets stuck a little bit when walking near columns and so on, may be thats cause I use box shape.
Posted By: EvilSOB

Re: PH_CHAR - 03/18/12 22:13

Hey 3run... Heres a simple test...

TRY using PH_CAPSULE instead of PH_BOX or your player.

But give it a thorough test. This MAY crearte new peoblems...
Posted By: 3run

Re: PH_CHAR - 03/18/12 23:14

Yeah, that fixes problem with friction, but creates new problems, to fix which, I'll probably need to rewrite whole movement script. So I better stick with PH_BOX for now.
Posted By: rojart

Re: PH_CHAR - 03/19/12 00:51

Originally Posted By: 3run
... but isn't it about PH_RIGID? ...

No, it's about PH_CHAR, CHARacter Controller. wink
Posted By: 3run

Re: PH_CHAR - 03/19/12 02:18

Quote:
No Direct Control: A rigid body is typically controlled with impulses or forces...
Really is it? laugh
Posted By: rojart

Re: PH_CHAR - 03/19/12 11:16

Of course, read especially this sentence here: "Let's here why PhysX is against Dynamic Character Controllers:"

I make an movie that show you the "Sample Character Controller":

(Click on the picture to see the movie. Best view on Google Chrome)


Do you believe me now?
Posted By: 3run

Re: PH_CHAR - 03/19/12 16:31

Yeah, I do belive you now grin Thank you for video. So, problem isn't solvable?
Posted By: 3run

Re: PH_CHAR - 03/21/12 11:52

For the problem with crawling, as I said, I've tried painkillers approach, but with PH_CHAR, it didn't work..
Download link
I hope, someone could share his / her experience / ideas about this.
Posted By: Wjbender

Re: PH_CHAR - 03/21/12 20:49

I was thinking would it be possible to use a animated convex hull ,or to add remove hull shapes during transition from stance to crawl ? Just randomly thinking of ideas here ..Also i thnk i remember having acces to newton bodys do we have acces to physx bodys for manipulation or is that not a feature of physx
Posted By: Wjbender

Re: PH_CHAR - 03/23/12 22:30

made some changes to your code dont know if you would
except the changes but it works,setting the crawl status
i leave up to you because i disabled it during testing
let me know if it works okay..send me your email adress
or may i uplaod it somewhere for you??
Posted By: 3run

Re: PH_CHAR - 03/24/12 07:13

Upload it right here, I'm interested.
Posted By: Wjbender

Re: PH_CHAR - 03/24/12 08:58

this one uses rigid for crawling
Code:
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
VECTOR move_vec;
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
// camera:
var cam_height = 25;
// crawling:
var crouch_timer = 0;
var crawling = 0;
var allow_stand = 1;
var crawl_old = 0;
// gravity:
var my_height;
var jump_time = 1;
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
ENTITY* c_hull;
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
function handle_crawl()
{
	VECTOR temp;
	vec_set(temp.x, my.x);
	temp.z = my.z + 20; // top point of BBOX
	trace_mode = IGNORE_ME | IGNORE_PASSABLE | USE_BOX;
	c_trace(my.x, temp, trace_mode);	
	draw_line3d(my.x,vector(255,255,255),100);
	draw_line3d(temp,vector(255,255,255),100);
	if(trace_hit)
	{
		allow_stand = 0; 
	}
	else
	{
		allow_stand = 1;
	}
	if(key_ctrl) // if ctrl is pressed
	{
/*		if(crouch_timer > -25)
		{
			crouch_timer -= 5 * time_step;
			if(crouch_timer > 100){crouch_timer = 100;}	
		}
		else
		{
			crawling = 1;
		}
		camera.z += crouch_timer;
*/
		crawling=1;
	}
	else
	{
/*		if(crouch_timer < 0)
		{
			if(allow_stand == 1)
			{
				crawling = 0;
				crouch_timer += 5 * time_step;
				camera.z += crouch_timer;
			}
			else
			{
				camera.z += crouch_timer;
			}
		}
*/
	crawling=0;
	}
}
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
function handle_camera()
{
	camera.pan -= 1 * mickey.x * time_step;
	camera.tilt -= 1 * mickey.y * time_step;
	camera.tilt = clamp(camera.tilt, -90, 90);
	//vec_set(camera.x, vector(my.x, my.y, my.z + cam_height));
	camera.x = my.x + fcos((camera.pan), fcos(camera.tilt, -100));
	camera.y = my.y + fsin((camera.pan), fcos(camera.tilt, -100));
	camera.z = my.z + fsin(camera.tilt, -100);		
	pXent_rotate(c_hull, vector(camera.pan, 0, 0), nullvector);
	// crawling:
	handle_crawl();		
}
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
function apply_gravity()
{
	VECTOR temp;
	VECTOR vec_min;
	vec_set(temp, my.x);
	temp.z -= 1000;
	trace_mode = IGNORE_ME | IGNORE_FLAG2 | IGNORE_PASSABLE | USE_BOX;
	c_trace(my.x, temp, trace_mode); 
	vec_for_min(vec_min, my);
	my_height = my.z + vec_min.z - target.z;			
	if(my_height > 20)
	{
		accelerate(move_vec.z, -6 * time_step, -0.5);
	}
	else
	{
		if(jump_time == 1)
		{
			move_vec.z = -(my_height / 1.2) + 2;
		 	move_vec.z = clamp(move_vec.z, -5, 5);
		}
	}
}
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
action hero()
{
	player = my;
	set(my,TRANSLUCENT);
	set(my,PASSABLE);
	wait(1);
	c_setminmax(my);	
	// create bbox shapes:
	ENTITY* c_stand = ent_create("bbox.mdl", vector(0, 0, -10000), NULL);
	ENTITY* c_crawl = ent_create("bbox.mdl", vector(0, 0, -10000), NULL);
	// scale it down:
	c_crawl.scale_z = 0.5;
	// make them passable and transparent:
	set(c_stand, PASSABLE | TRANSLUCENT);
	set(c_crawl, PASSABLE | TRANSLUCENT);
	// unregistered in physiX:
	pXent_settype(my, 0, 0);
	pXent_enable(my,0);
	// attach all parts:
	c_hull = c_stand;

	vec_set(c_hull.x, my.x);
	vec_set(c_hull.pan, my.pan);
	pXent_settype(c_crawl, 0, 0);
	pXent_settype(c_stand, PH_CHAR, PH_CAPSULE);
	wait(1);
	while(1)
	{
		DEBUG_VAR(crawling, 20);
		vec_set(my.x, c_hull.x);	
		// crawling shape:	
		if(crawl_old != crawling)
		{
			if(crawling == 1)
			{
				c_hull = c_crawl;
				vec_set(c_hull.x, my.x);
				vec_set(c_hull.pan, my.pan);
				pXent_settype(c_stand, 0, 0);
pXent_settype(c_crawl, PH_RIGID, PH_CAPSULE);//***********
pXent_setbodyflag(c_crawl,NX_BF_FROZEN_ROT , 1);//************
			}
			if(crawling == 0)
			{
				c_hull = c_stand;
				vec_set(c_hull.x, my.x);
				vec_set(c_hull.pan, my.pan);
				pXent_settype(c_crawl, 0, 0);
pXent_settype(c_stand, PH_CHAR, PH_CAPSULE);//************
			}
			crawl_old = crawling;
		}
		// movement:		
		if(crawling == 0)
		{
			move_vec.x = 10 * (key_w - key_s) * time_step * (1 + key_shift * 0.5);
			move_vec.y = 10 * (key_a - key_d) * time_step * (1 + key_shift * 0.5);
		}
		else
		{
			move_vec.x = 2 * (key_w - key_s) * time_step;
			move_vec.y = 2 * (key_a - key_d) * time_step;
		} 
		// gravity:
if(!crawling)	apply_gravity();//****************
		// apply all forces:
		pXent_move(c_hull, move_vec, nullvector);		
		// attach camera:
		handle_camera();
		// attach model parts:
		vec_set(c_stand.x, c_hull.x);
		vec_set(c_stand.pan, c_hull.pan);			
		vec_set(c_crawl.x, c_hull.x);
		vec_set(c_crawl.pan, c_hull.pan);			
		// attach visible model:
		vec_set(my.x, c_hull.x);		
		my.pan = camera.pan;
		wait(1);
	}
	// DEATH HERE
}
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////


i dont know how to use code blocks..
your crawl trace vector distance seems to be to short
i did another version wich only used ph_char but then
there seems to be a problem with jumptimer
im sure you will get it fixed the correct way as your controller
already seems very nice .
Posted By: 3run

Re: PH_CHAR - 03/24/12 09:21

Thank you, I'll give it a try. Please use code tags to post scrit next time laugh It'll be easier to read it.
Posted By: Wjbender

Re: PH_CHAR - 03/24/12 10:11

Thats what i meant with code block dnt knw how to do it ? And rigid wil cause other problems like friction etc
Posted By: 3run

Re: PH_CHAR - 03/24/12 13:24

["code] insert code here [/code]
* remove " and insert code
Posted By: Wjbender

Re: PH_CHAR - 03/24/12 16:38

cool thanks !
© 2024 lite-C Forums