weapon coding question?
Moderator: InsideQC Admins
6 posts
• Page 1 of 1
weapon coding question?
is it possible to make a traceattack type weapon ricochet able?
-

ceriux - Posts: 2223
- Joined: Sat Sep 06, 2008 3:30 pm
- Location: Indiana, USA
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:
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: Select all
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!
-

MauveBib - Posts: 634
- Joined: Thu Nov 04, 2004 1:22 am
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.

http://forums.inside3d.com/viewtopic.php?t=1146
You can either tell it to return the trace_plane_normal, or the proper richocet vector.
-

Dr. Shadowborg - InsideQC Staff
- Posts: 1110
- Joined: Sat Oct 16, 2004 3:34 pm
MauveBib wrote:
- Code: Select all
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: Select all
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.
- Wazat
- Posts: 771
- Joined: Fri Oct 15, 2004 9:50 pm
- Location: Middle 'o the desert, USA
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.
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!
-

MauveBib - Posts: 634
- Joined: Thu Nov 04, 2004 1:22 am
6 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest