simple weapon?

Posted By: zSteam

simple weapon? - 12/19/07 22:15

hi

i want to write a weapon script to push physic objects away. how can i solve this problem?

hallo

ich möchte ein waffenskript schreiben, damit ich physikobjekte wegstoßen kann. doch wie kann ich das erreichen?
Posted By: adoado

Re: simple weapon? - 12/20/07 12:05

Depends on what physics engine you are using, Newton or ODE?

If you are using newton, I found this code in one of my old projects:

Code:

var toss_speed=100;//push speed and force
var toss_force=25;
var react_dist=50; //player pushes objects closer than this distance


action NewtonBox()
{

.....

var body;
while(1)
{
body = NewtonGetBody (my);
if (body)
{
if(player) //if player exists on the level
{
if (vec_dist(my.x,player.x)<react_dist)
{
newtonImpulseRecord[0] = my.x;
newtonImpulseRecord[1] = my.y;
newtonImpulseRecord[2] = my.z;

newtonImpulseRecord[3] = player.x;
newtonImpulseRecord[4] = player.y;
newtonImpulseRecord[5] = player.z - 0.25;

newtonImpulseRecord[6] = toss_speed;

newtonImpulseRecord[7] = toss_force;

NewtonBodyAddImpulse (body, newtonImpulseRecord);
}
}
}
}
}



I cannot remember how good it worked, but it should get you started

Thanks,
Adoado
Posted By: zSteam

Re: simple weapon? - 12/20/07 17:19

hi thx for the answer ... but i want to use ODE
Posted By: xXxGuitar511

Re: simple weapon? - 12/20/07 18:25

What kind of push

..Like a force that continually pushes, or an impact (as if something hit it) ?
Posted By: zSteam

Re: simple weapon? - 12/20/07 18:41

an imapct.... i would like to write a actionshooter with physic objects like HL2
Posted By: xXxGuitar511

Re: simple weapon? - 12/21/07 19:14

...well then, let me take a look in the manual...


phent_addforceglobal (ENTITY* entity, VECTOR* vForce, VECTOR* vPos );


...I'm not entirely sure of this, but I think this is what you need. Of course set ENTITY to the target physics ent.

Set FORCE to the bullet direction, and it's magnitude to the force. To do the latter, use vec_normalize(vector, 1000); 1000 being a random guess for force

and vPOS to the point where it hit the entity.
© 2024 lite-C Forums