View previous topic :: View next topic |
Author |
Message |
ceriux

Joined: 06 Sep 2008 Posts: 969 Location: Florida, USA
|
Posted: Mon Jan 05, 2009 10:13 am Post subject: weapon coding question? |
|
|
is it possible to make a traceattack type weapon ricochet able? _________________ QuakeDB - Quake ModDB Group |
|
Back to top |
|
 |
MauveBib

Joined: 04 Nov 2004 Posts: 602
|
Posted: Mon Jan 05, 2009 11:52 am Post subject: |
|
|
Yes.
trace_plane_normal is your friend here, it can be used to calculate the angle of incidence, and hence the negative of the angle of reflection.
Here's a quick example I knocked up for bouncy lightning:
Code: |
void(vector start, vector direction, float bounces) Lightning_Bounce =
{
local entity tempent;
local vector old_endpos;
traceline (start, start + direction * 600, FALSE, self);
tempent = spawn ();
WriteByte (MSG_BROADCAST,SVC_TEMPENTITY);
WriteByte (MSG_BROADCAST,TE_LIGHTNING2);
WriteEntity (MSG_BROADCAST,tempent);
WriteCoord (MSG_BROADCAST,start_x);
WriteCoord (MSG_BROADCAST,start_y);
WriteCoord (MSG_BROADCAST,start_z);
WriteCoord (MSG_BROADCAST,trace_endpos_x);
WriteCoord (MSG_BROADCAST,trace_endpos_y);
WriteCoord (MSG_BROADCAST,trace_endpos_z);
LightningDamage (start, trace_endpos + direction * 4, self, 25);
if (!bounces)
{
remove (tempent);
return;
}
traceline (start, start + direction * 600, FALSE, self);
direction_x = direction_x * ((-2 * fabs(trace_plane_normal_x)) + 1);
direction_y = direction_y * ((-2 * fabs(trace_plane_normal_y)) + 1);
direction_z = direction_z * ((-2 * fabs(trace_plane_normal_z)) + 1);
Lightning_Bounce (trace_endpos, direction, bounces - 1);
remove (tempent);
};
void() W_FireLightning =
{
local vector org;
local float cells, num_bounces;
num_bounces = 2;
if (self.ammo_cells < 1)
{
self.weapon = W_BestWeapon ();
W_SetCurrentAmmo ();
return;
}
// explode if under water
if (self.waterlevel > 1)
{
cells = self.ammo_cells;
self.ammo_cells = 0;
W_SetCurrentAmmo ();
T_RadiusDamage (self, self, 35*cells, world);
return;
}
if (self.t_width < time)
{
sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
self.t_width = time + 0.6;
}
self.punchangle_x = -2;
self.currentammo = self.ammo_cells = self.ammo_cells - 1;
org = self.origin + '0 0 16';
Lightning_Bounce (org, v_forward, num_bounces);
};
|
_________________ Apathy Now! |
|
Back to top |
|
 |
Dr. Shadowborg Inside3D Staff

Joined: 16 Oct 2004 Posts: 726
|
Posted: Mon Jan 05, 2009 4:31 pm Post subject: |
|
|
Rebovec in here:
http://forums.inside3d.com/viewtopic.php?t=1146
You can either tell it to return the trace_plane_normal, or the proper richocet vector.
 _________________ "Roboto suggests Plasma Bazooka." |
|
Back to top |
|
 |
Wazat
Joined: 15 Oct 2004 Posts: 732 Location: Middle 'o the desert, USA
|
Posted: Sat Jan 10, 2009 5:46 pm Post subject: |
|
|
MauveBib wrote: | Code: |
void(vector start, vector direction, float bounces) Lightning_Bounce =
{
local entity tempent;
local vector old_endpos;
traceline (start, start + direction * 600, FALSE, self);
tempent = spawn ();
WriteByte (MSG_BROADCAST,SVC_TEMPENTITY);
WriteByte (MSG_BROADCAST,TE_LIGHTNING2);
WriteEntity (MSG_BROADCAST,tempent);
WriteCoord (MSG_BROADCAST,start_x);
WriteCoord (MSG_BROADCAST,start_y);
WriteCoord (MSG_BROADCAST,start_z);
WriteCoord (MSG_BROADCAST,trace_endpos_x);
WriteCoord (MSG_BROADCAST,trace_endpos_y);
WriteCoord (MSG_BROADCAST,trace_endpos_z);
LightningDamage (start, trace_endpos + direction * 4, self, 25);
if (!bounces)
{
remove (tempent);
return;
}
traceline (start, start + direction * 600, FALSE, self);
direction_x = direction_x * ((-2 * fabs(trace_plane_normal_x)) + 1);
direction_y = direction_y * ((-2 * fabs(trace_plane_normal_y)) + 1);
direction_z = direction_z * ((-2 * fabs(trace_plane_normal_z)) + 1);
Lightning_Bounce (trace_endpos, direction, bounces - 1);
remove (tempent);
}; |
|
Looks good, mauvebib. However, isn't that second traceline a bit inefficient? I know you need to set trace_plane_normal & endpos again since LightningDamage will reset it, but since the those are the only parts that you need to preserve you could just store them in a couple local vectors instead. In fact, old_endpos isn't used so we could just use it.
Also, I like specifying distance.
Code: |
void(vector start, vector direction, float dist, float bounces) Lightning_Bounce =
{
local entity tempent;
local vector old_normal, old_endpos;
traceline (start, start + direction * dist, FALSE, self);
old_normal = trace_plane_normal;
old_endpos = trace_endpos;
tempent = spawn ();
WriteByte (MSG_BROADCAST,SVC_TEMPENTITY);
WriteByte (MSG_BROADCAST,TE_LIGHTNING2);
WriteEntity (MSG_BROADCAST,tempent);
WriteCoord (MSG_BROADCAST,start_x);
WriteCoord (MSG_BROADCAST,start_y);
WriteCoord (MSG_BROADCAST,start_z);
WriteCoord (MSG_BROADCAST,trace_endpos_x);
WriteCoord (MSG_BROADCAST,trace_endpos_y);
WriteCoord (MSG_BROADCAST,trace_endpos_z);
LightningDamage (start, trace_endpos + direction * 4, self, 25);
if (!bounces)
{
remove (tempent);
return;
}
direction_x = direction_x * ((-2 * fabs(old_normal_x)) + 1);
direction_y = direction_y * ((-2 * fabs(old_normal_y)) + 1);
direction_z = direction_z * ((-2 * fabs(old_normal_z)) + 1);
Lightning_Bounce (old_endpos, direction, dist, bounces - 1);
remove (tempent);
}; |
_________________ When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work. |
|
Back to top |
|
 |
MauveBib

Joined: 04 Nov 2004 Posts: 602
|
Posted: Sat Jan 10, 2009 6:12 pm Post subject: |
|
|
yep, that makes more sense.
I was hacking about with a few ideas to get it to work, and left a few leftovers from previous versions in there I guess, sort of like the 'mpuff' variable in several of the weapon.qc functions.
Efficiency isn't one of my coding skills. _________________ Apathy Now! |
|
Back to top |
|
 |
Wazat
Joined: 15 Oct 2004 Posts: 732 Location: Middle 'o the desert, USA
|
Posted: Sun Jan 11, 2009 6:10 pm Post subject: |
|
|
The vestigial organs of the programming world -- a bane of mine as well.  _________________ When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work. |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2004 phpBB Group
|