|
|
Bullet impacting crate
#207249
05/18/08 18:10
05/18/08 18:10
|
Joined: Aug 2003
Posts: 716 Canada, Toronto
thegamedesigner
OP
User
|
OP
User
Joined: Aug 2003
Posts: 716
Canada, Toronto
|
Hello, I have some code in place for a crate, and a bullet hitting the crate, but I can't seem to figure out exactly what force I should give the crate.
I am trying to make the crate react to the bullet hit. Here is my code:
action crate_act { my.category = 11; phent_settype(my,ph_rigid,ph_box); phent_setmass(my,5,ph_box); //phent_enable(my,1); phent_setfriction (my, 40); phent_setdamping(my, 20, 20); phent_setelasticity (my, 0, 40); phent_setgroup(my, 1);//1,2,4,8,8 ph_selectgroup(1); }
... Bullet code (target is point of impact, sloc[3] is where the bullet came from): ... //Bullet has hit something, is it a crate? if(you.category == 11)//It is a crate. { var dir[3]; dir[0] = 1; vec_rotate(dir,vector(pan1[0],0,0)); vec_normalize(dir,60000*time); phent_addforcelocal(you,vector(320,0,0),target); } ...
This is going to be so useful when it's done, thanks for all help.
EDIT: Pan1[3] contains the bullet's current pan/tilt/roll.
Last edited by thegamedesigner; 05/18/08 18:11.
|
|
|
Re: Bullet impacting crate
[Re: thegamedesigner]
#207306
05/19/08 03:25
05/19/08 03:25
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
phent_addforceglobal (ENTITY* entity,VECTOR* vForce,VECTOR* vPos );
vForce being the direction and strength of the force: - vForce = normalize(target - source, strength);
And vpos being the position where it hit the entity: - vPos = target;
xXxGuitar511 - Programmer
|
|
|
Re: Bullet impacting crate
[Re: xXxGuitar511]
#207432
05/19/08 16:10
05/19/08 16:10
|
Joined: Aug 2003
Posts: 716 Canada, Toronto
thegamedesigner
OP
User
|
OP
User
Joined: Aug 2003
Posts: 716
Canada, Toronto
|
Alright, I fiddled with that, and ended up with this:
vec_set(dir,pan1);//pan1 is the .pan,tilt and roll of the bullet vec_inverse(dir); vec_normalize(dir, 25000); phent_addforceglobal (you,dir,target);
That seems to work, but there is something funny about it. Does it look like I got it right?
Thanks for the help btw,
|
|
|
Re: Bullet impacting crate
[Re: xXxGuitar511]
#207668
05/21/08 15:58
05/21/08 15:58
|
Joined: Aug 2003
Posts: 716 Canada, Toronto
thegamedesigner
OP
User
|
OP
User
Joined: Aug 2003
Posts: 716
Canada, Toronto
|
Sometimes when I fire fast at it, it becomes airborne. Fine, np, but sometimes it moves away from me, and other times it spins towards me.
I am going to increase the weight/decrease the force, so it can't become airborne, but it is annoying.
Anyway, thanks very much for you help, I have crates that move when you shoot them.
|
|
|
|