PhysX movement

Posted By: Vyshess

PhysX movement - 11/16/11 22:24

Hi @ all!

I started my next game and want to use the physic-engine.
everything works good except the player movement.
at first I was giving the player a box collision but that doesn`t works because, by running the skript, the player disappears suddenly or falls through the test-level(a hollow block),not sure what exactly happens.
So I was trying the capsule collision.at first it looks good.I see the player and can walk around..but there is something strange. I set the foots of the player exactly on the ground but if I push one of the movement-keys, the player model is suddenly a bit over the ground. apart from that the movement works very good.
thx for help laugh

my player-code:
Code:
action hero()
{
	var anim_percentage;

	pXent_settype(my, PH_CHAR, PH_CAPSULE); 

	set(my,SHADOW);
	wait(1);
  
	
	my.emask |= ENABLE_SCAN; // make the player sensitive to scanning
	player = my; // I'm the player
	
	
	while(players_health > 0)
	{
	
		//player movement//
       movement_speed.x = 10 * (key_cuu - key_cud) * time_step; // move the player using "cuu" and "cud"
	movement_speed.y = 10 * (key_cul - key_cur) * time_step; // move the player using "cur" and "cul"

       pXent_movechar(me, movement_speed, NULL, 0);
		///////////////////
		
		//player animation//
		if(key_cuu || key_cud)
		{
			if(movement_speed.x > 0){my.pan = 0;} // turn player to right
			if(movement_speed.x < 0){my.pan = 180;} // turn player to left
			anim_percentage += 7 * time_step;
			ent_animate(my, "walk", anim_percentage, ANM_CYCLE); // play the "walk" animation			
		}   
		
		if(key_cur || key_cul)
		{
			if(movement_speed.y > 0){my.pan = 90;} // turn player to right
			if(movement_speed.y < 0){my.pan = -90;} // turn player to left
			anim_percentage += 7 * time_step;
			ent_animate(my, "walk", anim_percentage, ANM_CYCLE); // play the "walk" animation			
		}   
		
		
		if (key_cuu + key_cud + key_cur + key_cul == 0) // none of the movement keys are pressed?
		{
			anim_percentage += 1.2 * time_step;
			ent_animate(my, "idle", anim_percentage, ANM_CYCLE); // play the "stand" animation
		}
		/////////////////////
	   
		on_l = plant_bomb;
		
		
		
	wait(1);
   }
}


Posted By: Roel

Re: PhysX movement - 11/17/11 09:29

it might be possible that the capsule is bigger than your model.
You can overcome this by scaling your model down, call phent settype, and then scale it back.
Posted By: Pappenheimer

Re: PhysX movement - 11/18/11 09:19

At the beginning of the function place "c_updatehull(me, 1);".
This should be sufficient to set the collision capsule to the size of the player.
A seldom but possible reason could be that a vertex of the model is placed beneath the model's feet.
Maybe, you can correct the height of the model with setting the min_z value manually, as well.
Posted By: Vyshess

Re: PhysX movement - 11/18/11 20:26

Thanks guys! Problem solved!!
Posted By: 3run

Re: PhysX movement - 11/18/11 23:00

Could you please share your experience?
Posted By: Vyshess

Re: PhysX movement - 11/19/11 19:15

@ 3run: oh sure! i forgot to post the answer, sorry ^^

i used Roal`s advice and it works very well!

Code:
action hero()
{
	my.scale_z = 0.1; //makes me smaller for a smaller hull

	pXent_settype(my, PH_CHAR, PH_CAPSULE); 

        my.scale_z = 1.0; //get back my original size
	...
}


Posted By: Vyshess

Re: PhysX movement - 11/27/11 18:12

hi! i had another problem!
can someone tell me how to use "pXent_addexplosion" correctly?
my player can place bombs. and this bombs should be blow away a box. i give the box this action:
Code:
action ph_box() // simple physics-based box
{
pXent_settype(my, PH_RIGID, PH_BOX); // this entity behaves like a box	
}



and the bomb has this function:
Code:
function bomb_behavior()
{

VECTOR bomb_pos;

	while(explo_time > bomb_wait_time) //after some seconds, the bomb explode
	{

		explo_time -= time_step/16;

		 pXent_settype(my, PH_RIGID, PH_SPHERE); // this entity behaves like a ball
	 	 pXent_setfriction(my, 100); 
  	 	 pXent_setelasticity(my, 10);
	 	 pXent_setdamping(my, 100,40);
		

		bomb_pos.x = my.x; //get the actually position of the bomb
		bomb_pos.y = my.y;
		bomb_pos.z = my.z;
		... //the rest of the code (explosion anim etc.)
	wait(1);
	}

pXent_addexplosion( my, bomb_pos, 1000,500); //values ok???
wait(-2);

ent_remove(my);
}



i spend some hours with that addexplosion and the values but it doesn`t work.the box doesn`t move. sometimes the box disappears or flys to another dimension, not sure what happend there.
Posted By: HeelX

Re: PhysX movement - 11/27/11 18:32

The values look right for my taste, except that 1000 as force parameter is very high... try to build a testcase with a room, the box and the possibility to place a bomb, upload it and we can have our hands on it.
Posted By: Ch40zzC0d3r

Re: PhysX movement - 11/28/11 14:37

Its tooo much.
My explsoion vars for a nade:
pXent_addexplosion(me,nullvector,200,300);
Posted By: Vyshess

Re: PhysX movement - 11/28/11 19:10

i know that 1000 is too much. in my desperation, i was trying some crazy values.
i set the force to 10 to see whats going on. the bomb flys like a rocket to the sky...okay maybe i misunderstand the "VECTOR*vPos" part.
so i replaced "bomb_pos" with "nullvector". and now it seems that the bomb is hit by an explosion an flys to a random direction. but the box is still uneffected...even by a radius with 2000!
Posted By: Roel

Re: PhysX movement - 11/28/11 20:48

Probably you should call the explosion function for every entity,
because pXent_addexplosion only affects it's own entity.
I got it working some time ago.
Posted By: Ch40zzC0d3r

Re: PhysX movement - 11/29/11 13:33

-_-
Just loop through all entities and do pXent_addexplosion.
Its so easy...
Posted By: Vyshess

Re: PhysX movement - 11/29/11 18:07

Ah!! that is what i wanted to know. it effects only it`s own entity.
that means the box (and any other entity that should be effected by the explosion) need pXent_addexplosion and not the bomb itself!

@Ch40zzC0d3r ...it isn`t so easy..it would be easy if the explosion of one entity hits all physical entities. But thanks for your help guys!!
Posted By: Ch40zzC0d3r

Re: PhysX movement - 11/29/11 18:28

No problem wink
Now to your new problem:
My solution was to make a c_scan and give the box the event for scan_detect. Now when it get scanned, i calculate the difference between the object and the explosion (position). Than I add this factor to the explosion and all is working fine.

BTW: It is so easy. Try what I said in the post above. All entities are looped and will "explode". I will test this now too.
Posted By: Vyshess

Re: PhysX movement - 11/29/11 18:42

okay i use c_scan and it works! but now i have another problem. the box flys to fast..even by a force of 5. so i set a mass for the box. 50 is a good value because the box behaves as i want.but now the box falls through the level. i tried different values. if i use 9 or less the box lands correctly on the ground. if mass is 10 or more, the box falls through the ground...is this a bug???
Posted By: Ch40zzC0d3r

Re: PhysX movement - 12/01/11 17:07

Just make the explo parameters smaller. Not just 1. Decrease both! This will work.
Posted By: Vyshess

Re: PhysX movement - 12/02/11 20:31

i decrease both! but this can`t be the reason, because even if i touch the box with the player, the box falls through the ground.
Posted By: Ch40zzC0d3r

Re: PhysX movement - 12/03/11 08:22

You should set the ground px_plate type!
When this dont works I dont really have an idea frown
Posted By: Vyshess

Re: PhysX movement - 12/04/11 18:48

suddenly it works...don`t know why...
okay, back to the movement of the player. the bomb (the box and other entities) falls down very realistic. but the player falls very fast and strange from a platform.and the bomb can land on other entities (like the box)..the player couldn`t. is it possible to fix that?
Posted By: Ch40zzC0d3r

Re: PhysX movement - 12/05/11 06:04

You need to set some infos about your player like mass etc.

Code:
pXent_setmass(my, 50);
pXent_setdamping (  my, 50, 50 );
pXent_setfriction(my, 20);



Hope this helps you.
Posted By: Vyshess

Re: PhysX movement - 12/05/11 21:03

i was trying that,but it has no effect on the player.
(thanks that your are helping me every day laugh hoffe es nervt nicht zu sehr wink )
Posted By: Ch40zzC0d3r

Re: PhysX movement - 12/06/11 05:05

Hm than I think its a bug. You should ask JCL for this physx bug.
What version of 3dgs you use actually?

BTW: (Kein Problem grin Ich helfe gern wink )
Posted By: Vyshess

Re: PhysX movement - 12/13/11 18:04

now i use V 8.30. i forgot to update A8...ähm..yes... But this makes my problem bigger `cause the player doesn`t fall down anymore.
actually i use "players_pos.Z -=2*time_step;" to get him on the ground but i think thats not a good answer! any ideas?
Posted By: Ch40zzC0d3r

Re: PhysX movement - 12/13/11 19:36

You are funny xD
When you use physx to move the player, than you dont need vmove gravity...
Just set the player as object not player in physx like your bomb...
So you need to recode the script for normal physx object not for playermovement laugh
Posted By: Vyshess

Re: PhysX movement - 12/14/11 18:05

höhö i know.thanks ^^
i don`t get it...okay lets see.
i have to replace " pXent_settype(my, PH_CHAR, PH_CAPSULE); " with
pXent_settype(my, PH_RIGID, PH_CAPSULE); ?
but i think "pXent_movechar(me, movement_speed, NULL, 0);" works only with "PH_CHAR"...i`m really confused
Posted By: Ch40zzC0d3r

Re: PhysX movement - 12/15/11 13:47

Yes you are 100% right. You need to do instead of
Code:
pXent_movechar(me, movement_speed, NULL, 0);


this:
Code:
pXent_move (ENTITY* entity, VECTOR* vReldist, VECTOR* vAbsdist)


And for rotate the same, than you have perfect gravity wink
Posted By: Vyshess

Re: PhysX movement - 12/15/11 20:14

hmm at the moment the player make some moves like a breakdancer..looks cool but he can`t walk normal.
my actually code for the movement:
Code:
movement_speed.x = 10 * (key_cuu_key_cud) * time_step;
movement_speed.y = 10 * (key_cuu_key_cud) * time_step;
movement_speed.z = 0;

pXent_move (me, movement_speed, NULL);


not sure whats wrong there. the example in the manual is too cryptic for me or it doesn`t work so good `cause if i use it, the player falls through the ground. maybe you have a simple and working example for me??

and when should I use CHAR and RIGID? the manual shows the differences but I`m not sure what I should use for my player.
Posted By: Ch40zzC0d3r

Re: PhysX movement - 12/16/11 12:43

Here is a little example for physx moevement, dont know if you want a FPS-movement.

DL: http://www.mediafire.com/?a3c28avep4un7nz

Hop ethis is what you want grin

BTW_ Creds goes to 3Run wink
© 2024 lite-C Forums