Physics help needed for controls similar to Half-Life 2

Posted By: Robogamer

Physics help needed for controls similar to Half-Life 2 - 06/17/14 15:35

Hello!

I need a code snippet for the following: when we click with the right mouse button on an entity, we pick it up, and we can carry it around (it is levitating in front of the camera). With the left mouse button, we can throw it away. But with pressing right mouse button again, while we carry that entity around, we can gently put it down on the ground. This solution was in Half-Life 2. Please help me!

Thanks in advance!
Posted By: sivan

Re: Physics help needed for controls similar to Half-Life 2 - 06/18/14 07:31

in your main user interface while loop check if mouse is clicked
check is there a mouse_ent
check whether it is a pickable entity or not (you can use a FLAG for it, set on level design)
use vec_for_vertex or vec_for_bone to position this item entity to your character hand (even if it is invisible)

on left click check whether the character has an item in hand
if yes, start throw animation of your character
when it is finished after some frames, set a speed to the item
decelerate item speed, apply gravitation, until hits something, or use physx

on right click check whether the character has an item in hand
if yes, detach from character, and set a gravity to the item
Posted By: Robogamer

Re: Physics help needed for controls similar to Half-Life 2 - 06/18/14 11:17

Thanks, but I'd like to use PhysX-
should I attach the entity to the player with an invisible rope, while the player carries the entity?
If yes, how can I do that?
Posted By: sivan

Re: Physics help needed for controls similar to Half-Life 2 - 06/19/14 07:15

I do not use physx, probably there are more experienced people around here.
Posted By: Wjbender

Re: Physics help needed for controls similar to Half-Life 2 - 07/03/14 21:36

one of my competition entries attached and
threw an object , it was called "moon craft" although I forgot to limit the frame rate to 60 fps
wich rendered my forces absolute , there is code
within it you could use , I used joints to do what
you describe. ..
Posted By: ventilator

Re: Physics help needed for controls similar to Half-Life 2 - 07/05/14 09:49

i would use a PID controller for such things.
http://forums.tigsource.com/index.php?topic=10130.0
(only using the P or PI parts could be enough too. :))
Posted By: Emre

Re: Physics help needed for controls similar to Half-Life 2 - 07/05/14 10:53

You can use pXent_setvelocity and pXent_addvelcentral. for example;

Code:
VECTOR hold_target;
VECTOR my_kick;
.....
if (event_type == EVENT_RIGHTCLICK)
	{
		while(mouse_right==1)
		{
			
			if(!mouse_left)
			{
				
				vec_set(hold_target,vector(20,0,0));
				vec_rotate(hold_target,camera.pan);
				vec_add(hold_target,camera.x);
				vec_sub(hold_target.x,my.x);
				vec_scale(hold_target.x,10);
				pXent_setvelocity(my, vector(hold_target.x, hold_target.y, hold_target.z)); 
				
				
			}
			else
			{
				
				
				my_kick.x=10;
				my_kick.y=0;my_kick.z=0;
				vec_rotate(my_kick,camera.pan);
				pXent_addvelcentral(my, vector(my_kick.x, my_kick.y, my_kick.z));
				
				break;
			}
			wait(1);
		}
		
	}

© 2024 lite-C Forums