PhysX enabled player character

Posted By: Sajeth

PhysX enabled player character - 06/24/11 10:39

Yep, I've been trying for days and can't find a way to get acceptable results.
NX_BF_KINEMATIC doesnt seem to work at all.
PH_CHAR provides acceptable movement BUT is very indifferent to its surrounding - walking up very steep ramps, pushing all objects aside disregarding their mass.
Using PH_BOX solves the problems PH_CHAR had; by disabling gravity for the player entity and using a custom gravity function I can also eliminate the problem of the player sliding around all the time - but this results in jerky movement.

So... anyone has any experience with this?
Posted By: Sajeth

Re: PhysX enabled player character - 06/25/11 10:03

Anyone tried anything like that yet?
Maybe I should just go with a c_move-Entity and use collision events to kick objects aside?
Posted By: 3run

Re: PhysX enabled player character - 06/25/11 10:09

I tried to make good, solid movement with those, and after few weeks I gave up...
I advice you to use "c_move" (but even this one is sucks, cause of ellipsoid hull).
Posted By: Sajeth

Re: PhysX enabled player character - 06/25/11 12:43

Irgendwie werd ich generell mit der PhysX-Implementierung nicht glücklich... das kommt alles irgendwie immer aufs selbe raus, die ganzen Parameter haben nur minimalste Auswirkungen...
Posted By: 3run

Re: PhysX enabled player character - 06/25/11 19:36

Sorry I don't know German, but Google translator helped me this time laugh
I have to agree, I don't like PhysX implementation too. I played alot with car physics, but no realistic results...
Posted By: Meerkat

Re: PhysX enabled player character - 06/26/11 09:44

Also PhysX für Bälle zu benutzen da kann ich mich nicht beschweren. Da wirkt das alles recht gut. Der andere Krams kommt ja noch auf mich zu. Sollte das so sein wie ihr sagt, dann hoffe ich das da noch ordentlich ausgebessert wird. laugh
Posted By: AlexMP

Re: PhysX enabled player character - 06/26/11 10:31

I did this using a sphere, but there is no colision for the upper part of the body.
Posted By: Sajeth

Re: PhysX enabled player character - 06/26/11 11:22

How did you solve the problem with the Player sliding around whenever the ground is not perfectly even? Or didnt you?
Posted By: MasterQ32

Re: PhysX enabled player character - 06/26/11 13:47

hey guys!
i've done some more advanced player code with physX wink
it's very good and i solved the sliding problem
i don't have time to extract all unneccessary things, but here you go:
Code:
action phys_actor()
{
	ent_playerphysic = me;
	set(me,INVISIBLE | PHYSIC_DUMMY);
	pXent_settype(me,PH_RIGID,PH_BALL);
	pXent_setmass(me,76);
	
	VECTOR temp;
	VECTOR mov;
	VECTOR vel;
	
	on_space = phys_actor_jump;
	on_mouse_left = actor_weaponprimary;
	on_mouse_right = actor_weaponsecondary;
	on_r = actor_weaponreload;
	
	on_1 = actor_getweapon1;
	on_2 = actor_getweapon2;
	on_3 = actor_getweapon3;
	
	var time = 0;
	
	my.CAMERA_PAN = camera.pan;
	my.CAMERA_TILT = camera.tilt;
	
	var fall_damage_last_z = my.z;
	var fall_damage_distance = 0;
	var fall_damage_last_distance = 0;
	var fall_damage_testtime = 1;
	
	var movement_time = 0;
	
	while(me)
	{
		my.CAMERA_PAN -= 2 * mouse_force.x / (1 + 3 * var_sniper_zoomed);
		my.CAMERA_TILT = clamp(my.CAMERA_TILT + 2 * mouse_force.y / (1 + 3 * var_sniper_zoomed),-90,90);
		
		time += 0.125 * time_step;
		
		camera.pan = my.CAMERA_PAN + 0.5 * sin(0.125 * time);
		camera.tilt = my.CAMERA_TILT + 0.5 * cos(0.25 * time);
		
		switch(var_weapon_selected)
		{
			case WEAPON_SNIPER:
				ent_weapon_sniper.flags2 |= SHOW;
				ent_weapon_pistol.flags2 &= ~SHOW;
				ent_weapon_knife.flags2 &= ~SHOW;
				if(var_sniper_bullets > 0)
				{
					pan_weapon_sniperbullets.size_x = var_sniper_bullets * 16;
					set(pan_weapon_sniperbullets,SHOW);
				}
				else
				{
					reset(pan_weapon_sniperbullets,SHOW);
				}
				reset(pan_weapon_pistolbullets,SHOW);
				break;
			case WEAPON_PISTOL:
				ent_weapon_sniper.flags2 &= ~SHOW;
				ent_weapon_pistol.flags2 |= SHOW;
				ent_weapon_knife.flags2 &= ~SHOW;
				var_sniper_zoomed = 0;
				reset(pan_weapon_sniperbullets,SHOW);
				if(var_pistol_bullets > 0)
				{
					pan_weapon_pistolbullets.size_x = var_pistol_bullets * 17;
					set(pan_weapon_pistolbullets,SHOW);
				}
				else
				{
					reset(pan_weapon_pistolbullets,SHOW);
				}
				
				break;
			case WEAPON_KNIFE:
				ent_weapon_sniper.flags2 &= ~SHOW;
				ent_weapon_pistol.flags2 &= ~SHOW;
				ent_weapon_knife.flags2 |= SHOW;
				var_sniper_zoomed = 0;
				reset(pan_weapon_sniperbullets,SHOW);
				reset(pan_weapon_pistolbullets,SHOW);
				break;
			case WEAPON_EMPTY:
				ent_weapon_sniper.flags2 &= ~SHOW;
				ent_weapon_pistol.flags2 &= ~SHOW;
				ent_weapon_knife.flags2 &= ~SHOW;
				var_sniper_zoomed = 0;
				reset(pan_weapon_sniperbullets,SHOW);
				reset(pan_weapon_pistolbullets,SHOW);
				break;
		}
		
		if(var_sniper_zoomed)
		{
			var_sniper_zoomfac = clamp(var_sniper_zoomfac - mickey.z / 60,5,40);
		}
		else
		{
			var_weapon_selected = cycle(var_weapon_selected - mickey.z / 120,0,4);
		}
		
		if(key_w || key_s || key_a || key_d)
		{
			vec_set(mov,vector((key_w - key_s) * 150 * time_step,(key_a - key_d) * 100 * time_step,0));
			vec_rotate(mov,vector(camera.pan,0,0));
			pXent_getvelocity(me,vel,nullvector);
			vel.x = -1 * vel.x * time_step + mov.x;
			vel.y = -1 * vel.y * time_step + mov.y;
			vel.z = 0;
			pXent_addvelcentral(me,vel);
			pXent_addvelcentral(me,mov);
			
			movement_time = 4;
		}
		else
		{
			pXent_getvelocity(me,vel,nullvector);
			vel.x = -1 * vel.x * time_step;
			vel.y = -1 * vel.y * time_step;
			if(c_trace(ent_playerphysic.x,vector(ent_playerphysic.x,ent_playerphysic.y,ent_playerphysic.z - 20),IGNORE_PASSABLE | IGNORE_ME) && !phys_actor_jumping)
			{
				vel.z = -1 * vel.z * time_step;
			}
			else
			{
				vel.z = 0;
			}
			pXent_addvelcentral(me,vel);
			movement_time -= time_step;
		}
		
		if(movement_time < 0)
		{
			pXent_setbodyflag(me,NX_BF_FROZEN_POS_X,1);
			pXent_setbodyflag(me,NX_BF_FROZEN_POS_Y,1);
		}
		else
		{
			pXent_setbodyflag(me,NX_BF_FROZEN_POS_X,0);
			pXent_setbodyflag(me,NX_BF_FROZEN_POS_Y,0);
		}
		
		
		vec_set(ent_playerdummy.x,my.x);
		ent_playerdummy.z += 22;
		
		vec_set(camera.x,ent_playerdummy.x);
		camera.z += 32;
		
		ent_playerdummy.pan = camera.pan;
		
		if(var_sniper_zoomed)
		{
			camera.arc = var_sniper_zoomfac;
			set(pan_weapon_sniperscope,SHOW);
			//set(pan_weapon_snipertarget,SHOW);
			
			VECTOR target_pos;
			weapon_sniper_gethitpoint(target_pos,camera.x,camera.pan);
			vec_to_screen(target_pos,camera);
			pan_weapon_snipertarget.pos_x = target_pos.x - 7;
			pan_weapon_snipertarget.pos_y = target_pos.y - 7;
			
			var scale_x = screen_size.x / bmap_width(pan_weapon_sniperscope.bmap);
			var scale_y = screen_size.y / bmap_height(pan_weapon_sniperscope.bmap);
			
			pan_weapon_sniperscope.scale_x = scale_x;
			pan_weapon_sniperscope.scale_y = scale_y;
			
			ent_weapon_sniper.flags2 &= ~SHOW;
			
			VECTOR from;
			VECTOR to;
			
			vec_set(from,camera.x);
			
			vec_set(to,vector(var_sniper_range,0,0));
			vec_rotate(to,camera.pan);
			vec_add(to,camera.x);
			
			var dist = c_trace(from,to,IGNORE_PASSABLE | IGNORE_ME);
			
			VECTOR center;
			vec_set(center,screen_size.x);
			vec_scale(center,0.5);
			
			draw_line(vector(center.x - 350 * scale_x, center.y,0),COLOR_RED,0);
			draw_line(vector(center.x - 350 * scale_x, center.y,0),COLOR_RED,100);
			draw_line(vector(center.x - 25, center.y,0),COLOR_RED,100);
			draw_line(vector(center.x - 25, center.y,0),COLOR_RED,0);
			
			draw_line(vector(center.x + 25, center.y,0),COLOR_RED,0);
			draw_line(vector(center.x + 25, center.y,0),COLOR_RED,100);
			draw_line(vector(center.x + 350 * scale_x, center.y,0),COLOR_RED,100);
			draw_line(vector(center.x + 350 * scale_x, center.y,0),COLOR_RED,0);
			
			draw_line(vector(center.x,center.y - 350 * scale_y,0),COLOR_RED,0);
			draw_line(vector(center.x,center.y - 350 * scale_y,0),COLOR_RED,100);
			draw_line(vector(center.x,center.y - 25,0),COLOR_RED,100);
			draw_line(vector(center.x,center.y - 25,0),COLOR_RED,0);
			
			draw_line(vector(center.x,center.y + 25,0),COLOR_RED,0);
			draw_line(vector(center.x,center.y + 25,0),COLOR_RED,100);
			draw_line(vector(center.x,center.y + 350 * scale_y,0),COLOR_RED,100);
			draw_line(vector(center.x,center.y + 350 * scale_y,0),COLOR_RED,0);
			
			draw_text(str_printf(NULL,"Distanz: %im",(int)dist / 64),center.x + 25,center.y - 17,COLOR_WHITE);
			
			VECTOR temp;
			vec_set(temp,vWind);
			vec_rotate(temp,vector(-camera.pan,0,0));
			
			var debug_wind = center.x - temp.y * 4;
			
			draw_line(vector(center.x,16,0),COLOR_BLUE,0);
			draw_line(vector(center.x,16,0),NULL,100);
			draw_line(vector(center.x,32,0),COLOR_BLUE,100);
			draw_line(vector(center.x,32,0),COLOR_BLUE,0);
			
			draw_line(vector(debug_wind,16,0),COLOR_GREEN,0);
			draw_line(vector(debug_wind,16,0),NULL,100);
			draw_line(vector(debug_wind,32,0),COLOR_GREEN,100);
			draw_line(vector(debug_wind,32,0),COLOR_GREEN,0);
		}
		else
		{
			camera.arc = 60;
			reset(pan_weapon_sniperscope,SHOW);
			reset(pan_weapon_snipertarget,SHOW);
		}
		
		var_weapon_shottime -= time_step;
		
		if(fall_damage_testtime < 0)
		{
			fall_damage_distance = my.z - fall_damage_last_z;
			
			if((fall_damage_distance - fall_damage_last_distance) > 35)
				ent_playerdummy.HEALTH -= 4;
				
			fall_damage_last_z = my.z;
			fall_damage_last_distance = fall_damage_distance;
			fall_damage_testtime = 2;
		}
		
		fall_damage_testtime -= time_step;
	
		wait(1);
	}
}


Posted By: Sajeth

Re: PhysX enabled player character - 06/26/11 15:42

Okay, very good idea - I'm gonna try doing something similar with NX_BF_FROZEN-flags! Thanks for sharing your code!
Posted By: painkiller

Re: PhysX enabled player character - 06/27/11 23:29

I'm working on a PhysX-based movement using PH_RIGID and PH_CAPSULE, as soon as I get good results I will post it here.
Posted By: painkiller

Contribution: PhysX enabled player character - 06/28/11 11:33

ok, here is the player movement code using PhysX: http://www.mediafire.com/?zgji7nizozqk748

Includes walking, running (shift key) and jumping. As player is PH_RIGID, you can have many advantages, such as:
-proper inertia when jumping of falling
-correct interaction with other movable objects, such as boxes
-player speed on high slopes is lower
Posted By: Random

Re: Contribution: PhysX enabled player character - 07/06/11 07:44

There is a little problem.
You are not able use this with any object (charekter).
Some work, some not.
For exsample;
The FBI model from Intense X works.
But the free soldier model ( maby you know it from "Assault") doesn`t work.

Does anybody has an idea, why this is?

PS; But it works great!
© 2024 lite-C Forums