Hitscan ricocheting?
Moderator: InsideQC Admins
6 posts
• Page 1 of 1
Hitscan ricocheting?
Guys, does someone know how to make a hitscan weapon ricochet its shots instantly using traceline()?
Thanks!
Thanks!
-

Orion - Posts: 476
- Joined: Fri Jan 12, 2007 6:32 pm
- Location: Brazil
Basic idea:
Trace the first shot.
Check to see if you hit something that you want to do damage to.
Copy all of the relevant trace_* variables (anything you want to keep, as they're about to be overwritten)
Use trace_endpos to work out where first contact is.
Optionally use trace_fraction to see how much further the bullet can travel.
Reflect the angle of the shot about trace_plane_normal (this is the tricky part)
Trace the next shot.
Lather, rinse, repeat as necessary.
How to actually get the angle to travel away at is the tricky part. Hopefully, someone like Dr. Shadowborg will come along and read this, because he's done bouncing weapons before, and they involve doing a short traceline to get trace_plane_normal as well. The first mission pack has the laser cannon, which has bouncing laser bolts, but code contains a bug which means that the angle created is incorrect. It's fairly easy to fix, though.
Of course, DP_MOVETYPEBOUNCEMISSILE takes all of the hassle out of bouncing lasers, but it also takes out all of the learning possibilities...
Trace the first shot.
Check to see if you hit something that you want to do damage to.
Copy all of the relevant trace_* variables (anything you want to keep, as they're about to be overwritten)
Use trace_endpos to work out where first contact is.
Optionally use trace_fraction to see how much further the bullet can travel.
Reflect the angle of the shot about trace_plane_normal (this is the tricky part)
Trace the next shot.
Lather, rinse, repeat as necessary.
How to actually get the angle to travel away at is the tricky part. Hopefully, someone like Dr. Shadowborg will come along and read this, because he's done bouncing weapons before, and they involve doing a short traceline to get trace_plane_normal as well. The first mission pack has the laser cannon, which has bouncing laser bolts, but code contains a bug which means that the angle created is incorrect. It's fairly easy to fix, though.
Of course, DP_MOVETYPEBOUNCEMISSILE takes all of the hassle out of bouncing lasers, but it also takes out all of the learning possibilities...
-

Lardarse - Posts: 266
- Joined: Sat Nov 05, 2005 1:58 pm
- Location: Bristol, UK
I see.
For a projectile weapon ricochet, it generally uses in the touch function (self.velocity = old_velocity + 2*trace_plane_normal;).
And then, I created an entity which will spawn at trace_endpos, and its angles set to vectoangles(2*trace_plane_normal), and then doing another traceline using makevectors() with the entity's angles and trace using v_forward.
Here are some screenshots, but the shot won't ricochet if fired on the ground... But that's ok. Works just like HL's Gauss Gun (which doesn't ricochet ground shots).




For a projectile weapon ricochet, it generally uses in the touch function (self.velocity = old_velocity + 2*trace_plane_normal;).
And then, I created an entity which will spawn at trace_endpos, and its angles set to vectoangles(2*trace_plane_normal), and then doing another traceline using makevectors() with the entity's angles and trace using v_forward.
Here are some screenshots, but the shot won't ricochet if fired on the ground... But that's ok. Works just like HL's Gauss Gun (which doesn't ricochet ground shots).




-

Orion - Posts: 476
- Joined: Fri Jan 12, 2007 6:32 pm
- Location: Brazil
Orion wrote:For a projectile weapon ricochet, it generally uses in the touch function (self.velocity = old_velocity + 2*trace_plane_normal;).
That formula looks a little wrong, but I can't be sure exactly what's wrong with it. You may want to read this for more info.
-

Lardarse - Posts: 266
- Joined: Sat Nov 05, 2005 1:58 pm
- Location: Bristol, UK
acording to quake:
newvel = oldvel - (oldvel*planenormal)*2*planenormal;
Where 'vel' can be a direction.
This preserves speed.
Changing the 2 to 1 makes it slide along the plane. Changing it to 1.5 makes it bounce as much as a grenade does. Leaving it as 2 makes it a full bounce. Using 2.5 is silly. 5 is absurd.
newvel = oldvel - (oldvel*planenormal)*2*planenormal;
Where 'vel' can be a direction.
This preserves speed.
Changing the 2 to 1 makes it slide along the plane. Changing it to 1.5 makes it bounce as much as a grenade does. Leaving it as 2 makes it a full bounce. Using 2.5 is silly. 5 is absurd.
- Spike
- Posts: 2892
- Joined: Fri Nov 05, 2004 3:12 am
- Location: UK
6 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
