Forum

Hitscan ricocheting?

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

Hitscan ricocheting?

Postby Orion » Wed Oct 01, 2008 11:50 pm

Guys, does someone know how to make a hitscan weapon ricochet its shots instantly using traceline()?
Thanks!
User avatar
Orion
 
Posts: 476
Joined: Fri Jan 12, 2007 6:32 pm
Location: Brazil

Postby Lardarse » Thu Oct 02, 2008 6:54 am

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...
User avatar
Lardarse
 
Posts: 266
Joined: Sat Nov 05, 2005 1:58 pm
Location: Bristol, UK

Postby Orion » Thu Oct 02, 2008 5:20 pm

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).


ImageImage

ImageImage

ImageImage
User avatar
Orion
 
Posts: 476
Joined: Fri Jan 12, 2007 6:32 pm
Location: Brazil

Postby Lardarse » Thu Oct 02, 2008 7:26 pm

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.
User avatar
Lardarse
 
Posts: 266
Joined: Sat Nov 05, 2005 1:58 pm
Location: Bristol, UK

Postby Dr. Shadowborg » Thu Oct 02, 2008 7:34 pm

Look around in here for ReboVec.

http://forums.inside3d.com/viewtopic.php?t=1146
User avatar
Dr. Shadowborg
InsideQC Staff
 
Posts: 1110
Joined: Sat Oct 16, 2004 3:34 pm

Postby Spike » Thu Oct 02, 2008 7:54 pm

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.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest