Impacts in water using darkplaces
Impacts in water using darkplaces
Hello forum!, I've been doing a pack of materials for the impacts according to the texture. But I have a question: is there any way to know that a Traceline touches the liquid via qc?
I just want to hit bullets into the water and there put a sprite or particles. But the bullet continue his career once touch the water. Is there any way to do this? I am using darkplaces, thanks in advance:)
I just want to hit bullets into the water and there put a sprite or particles. But the bullet continue his career once touch the water. Is there any way to do this? I am using darkplaces, thanks in advance:)
hi, I am nahuel, I love quake and qc.
Re: Impacts in water using darkplaces
I don't know if this helps, but you could use
if (trace_inwater) {
You could also try using an actual projectile (like a spike or missile) moving at very high velocity instead of a traceline (note: to do this I think you have to alter sv_maxspeed or something like that). That way you might be able to detect something like..
if ((projectile.flags) == FL_INWATER) {
WaterSplash();
}
Using an actual projectile can also be cool because you can create bullet drop at extreme distances. Just an idea anyway.
Alex
if (trace_inwater) {
You could also try using an actual projectile (like a spike or missile) moving at very high velocity instead of a traceline (note: to do this I think you have to alter sv_maxspeed or something like that). That way you might be able to detect something like..
if ((projectile.flags) == FL_INWATER) {
WaterSplash();
}
Using an actual projectile can also be cool because you can create bullet drop at extreme distances. Just an idea anyway.
Alex
Re: Impacts in water using darkplaces
Dear Nahuel,
There is this tutorial from Tux:
http://inside3d.com/showtutorial.php?id=15
He uses "pointcontens" to check for water and spawns a splash (as impact).
You could extend this for different materials / textures of course.
Maybe this helps you.
Best wishes my friend.
Seven.
There is this tutorial from Tux:
http://inside3d.com/showtutorial.php?id=15
He uses "pointcontens" to check for water and spawns a splash (as impact).
You could extend this for different materials / textures of course.
Maybe this helps you.
Best wishes my friend.
Seven.
Last edited by Seven on Mon Nov 14, 2011 3:41 pm, edited 1 time in total.
Re: Impacts in water using darkplaces
Far as I understand it, that tutorial works for entities, you'd need to create a dummy entity for hitscan weapons like the Shotguns.
Imagine if you will, you fire the shotgun, normal hitscan bullets do their thing, but you also spawn a single nail spike in the fireshotgun routine, if using darkplaces, (and maybe other engines, i dunno) you can set this nail spike to be invisible easily using .alpha, or maybe even EF_NODRAW (the nail spike wouldnt need to be sent to clients as an entity, as we only care for the point where it intersects the water brush for spawning the splash effect.)
( This concept is a combination of the tutorial posted by seven ofcourse, along with Alex's idea. )
Could you not also use Alex's idea, and use traceline(), check if trace_inwater == true, then use the traceline_endpos and travel back along the trace'd line, till your pointcontents() say your out of the water, maybe do it in decent size steps the first pass, then small steps to find a more exact position of the intersection of the waterbrush?
That tutorial + spawning an extra projectile for hitscan weapons just *sounds* slow and heavy, compared to doing a couple of extra tracelines, but I could easily be wrong.
Imagine if you will, you fire the shotgun, normal hitscan bullets do their thing, but you also spawn a single nail spike in the fireshotgun routine, if using darkplaces, (and maybe other engines, i dunno) you can set this nail spike to be invisible easily using .alpha, or maybe even EF_NODRAW (the nail spike wouldnt need to be sent to clients as an entity, as we only care for the point where it intersects the water brush for spawning the splash effect.)
( This concept is a combination of the tutorial posted by seven ofcourse, along with Alex's idea. )
Could you not also use Alex's idea, and use traceline(), check if trace_inwater == true, then use the traceline_endpos and travel back along the trace'd line, till your pointcontents() say your out of the water, maybe do it in decent size steps the first pass, then small steps to find a more exact position of the intersection of the waterbrush?
That tutorial + spawning an extra projectile for hitscan weapons just *sounds* slow and heavy, compared to doing a couple of extra tracelines, but I could easily be wrong.
I'm looking for a Mapper, Modeller/Animator and a Sound effect/Music person, to work on an exciting project. PM Me here, or catch me on IRC for further info.
Re: Impacts in water using darkplaces
it would be possible to mod the engine such that water leafs block traces as solid leafs do, as well as have empty leafs block traces (so you can do splashes when shooting out of water too).
note that dp has a .float dphitcontentsmask; field somewhere, which you can temporarily set to DP-specific content-mask value to achieve something like Q2 has, which is quite hacky and won't work properly on the e4 puddle on start.bsp, and will likely misbehave in teleporters too.
note that dp has a .float dphitcontentsmask; field somewhere, which you can temporarily set to DP-specific content-mask value to achieve something like Q2 has, which is quite hacky and won't work properly on the e4 puddle on start.bsp, and will likely misbehave in teleporters too.
Re: Impacts in water using darkplaces
Following on from what I posted earlier, I knocked up some quick, and I do mean QUICK, QC to demonstrate my method.
In weapons.qc, above W_FireShotgun, I added this:
And at the end of W_FireShotgun, after FireBullets() :
This will now put a bubble sprite at the top of the waterplane pretty close (its not perfect, but damn near it) to the water intersection, observe screenshots:

(Before shooting)

(After shooting, view angle 1)

(After shooting, view angle 2)
Now, I also did my own version for entities, well, the Grenade, dunno if it's the best method, that tutorial might be better, I *think* mine would be faster tho, but it comes at the cost of alot of .thinks(). So maybe it's slower? No idea, but it seems to work. ( Considering I knocked this up in about an hour or two... )
Firstly, in defs.qc, at the bottom, I added the following:
Then, in weapons.qc, above W_FireGrenade:
Then, in W_FireGrenade, near the bottom, I modified these bits:
And now, the grenade will leave a blue bubble where it's splash impact would be, at the top of the water. The method for the grenade (other entities should work the same with similar modifications), the splash impact is even less realistic than the shotgun bullets method, but as you can see from the code, it allows the grenade to create re-splashes if it exits and re-enters water. Screenshots:

( Before shooting. )

( After shooting, notice the extra splash bubble.... )
My method should work for any entities as needed, aswell as hitscan weapons. ( LG mega blast on water impact, anyone? )
In weapons.qc, above W_FireShotgun, I added this:
Code: Select all
// Make yours better than this shit.
void ( vector org ) spawn_splash =
{
local entity spot;
spot = spawn();
spot.origin = org;
spot.classname = "splash";
setmodel (spot, "progs/s_bubble.spr");
spot.flags = FL_ITEM;
spot.movetype = MOVETYPE_NONE;
}
/*
=========================
W_BulletSplash
=========================
*/
void( vector dir ) W_BulletSplash =
{
local vector shot_src;
local float steps;
local float stepsize;
local float shot_length;
local float old_contents;
// How far the bullets travel, FireBullets has this as 2048
shot_length = 2048;
// How large the check step is, larger = less accurate, but faster probably.
// Keep this as a multiple of 2, ie, 2, 4, 8, 16, 32, ...
stepsize = 2;
// This calculates the correct stepping between shot_length and stepsize;
steps = shot_length / stepsize;
// Nicked from FireBullets, but we increase the Z a little, for strange situations when stood in water... o.O
shot_src = self.origin + v_forward*10;
shot_src_z = self.absmin_z + self.size_z * 0.75;
// If the 'gun' is underwater here, we wont make a splash...
if ( pointcontents(shot_src) == CONTENT_WATER )
{
//bprint("Hmm, shot started in water...\n");
return;
}
// This may not be needed, but meh, it seems to work... o.o
old_contents = pointcontents(shot_src);
// K, trace the line to the end of the shot
traceline( shot_src, shot_src + dir * shot_length, FALSE, self );
// We in water?
if ( trace_inwater )
{
//bprint("Hit in water!\n");
// Now, we'l check the traceline, till we find the point we enter the water
while ( steps > 0 )
{
shot_src = shot_src + dir * stepsize;
if ( (pointcontents(shot_src) == CONTENT_WATER) && ( old_contents != CONTENT_WATER) )
{
//bprint("In Water!\n");
// Here, is where you would spawn your splash effect, shot_src is the closest origin to the
// water brush intersection of the bullets our trace stepper has found.
spawn_splash(shot_src);
// All done here
return;
}
steps = steps - 1;
}
}
};
Code: Select all
W_BulletSplash( dir );

(Before shooting)

(After shooting, view angle 1)

(After shooting, view angle 2)
Now, I also did my own version for entities, well, the Grenade, dunno if it's the best method, that tutorial might be better, I *think* mine would be faster tho, but it comes at the cost of alot of .thinks(). So maybe it's slower? No idea, but it seems to work. ( Considering I knocked this up in about an hour or two... )
Firstly, in defs.qc, at the bottom, I added the following:
Code: Select all
// Water splashable entities
.void() old_think;
.float old_nextthink;
.float old_contentz;
Code: Select all
void() GrenadeSplash =
{
local float step_length;
local float stepsize;
local float steps;
local vector nade_origin;
local float pointcontents_now;
// Reduce amount of times we have to call this...
pointcontents_now = pointcontents( self.origin );
if ( (pointcontents_now == CONTENT_WATER) && ( self.old_contentz != CONTENT_WATER ) )
{
// We've entered water, splash time...
// Now, due to the odd way we do this, we'l traceline directly UP the Z, to find the point where the water intersection actually is...
step_length = 256; // This should be more than enough...
stepsize = 2;
steps = step_length / stepsize;
nade_origin = self.origin;
nade_origin_z = nade_origin_z = 4;
while ( steps > 0 )
{
nade_origin_z = nade_origin_z + stepsize;
if ( pointcontents(nade_origin) != CONTENT_WATER )
{
spawn_splash( nade_origin );
steps = 0;
}
steps = steps - 1;
}
/* If you enable this, you limit the nade to only one splash
// Reset thinks
self.think = self.old_think;
self.nextthink = time + (self.old_nextthink - time);
self.old_nextthink = -1;
return;*/
// Allow resplash...
self.old_contentz = CONTENT_WATER;
self.nextthink = time + 0.05;
return;
}
// Resplash....
if ( ( pointcontents_now != CONTENT_WATER ) && ( self.old_contentz == CONTENT_WATER ) )
{
self.old_contentz = CONTENT_EMPTY;
}
self.nextthink = time + 0.05;
// Force explode even if we didnt hit water....
if ( ( time > self.old_nextthink ) && ( self.old_nextthink != -1 ) )
{
self.think = self.old_think;
self.nextthink = time + 0.1;
}
};
Code: Select all
// set missile duration
// missile.nextthink = time + 2.5;
// missile.think = GrenadeExplode;
// Water Splashing nades
missile.nextthink = time + 0.05;
missile.think = GrenadeSplash;
// Original stuff
missile.old_think = GrenadeExplode;
missile.old_nextthink = time + 2.5;

( Before shooting. )

( After shooting, notice the extra splash bubble.... )
My method should work for any entities as needed, aswell as hitscan weapons. ( LG mega blast on water impact, anyone? )
I'm looking for a Mapper, Modeller/Animator and a Sound effect/Music person, to work on an exciting project. PM Me here, or catch me on IRC for further info.
Re: Impacts in water using darkplaces
[quote="Qrv"][/quote]
Thank you!! Very nice work!! I just add some pointparticles!!!
Thank you!! Very nice work!! I just add some pointparticles!!!
hi, I am nahuel, I love quake and qc.
Re: Impacts in water using darkplaces
Hey, no prob buddy.
You'l obviously need to re-work that QC some, to support other entities/weapons. Maybe even make a simplified manager for entities to track them hitting liquids.
Something else you'l need to edit there, mine only checks for pure WATER, not LAVA, SLIME, But yeah, have fun with it.
You'l obviously need to re-work that QC some, to support other entities/weapons. Maybe even make a simplified manager for entities to track them hitting liquids.
Something else you'l need to edit there, mine only checks for pure WATER, not LAVA, SLIME, But yeah, have fun with it.
I'm looking for a Mapper, Modeller/Animator and a Sound effect/Music person, to work on an exciting project. PM Me here, or catch me on IRC for further info.
Re: Impacts in water using darkplaces
Hello Qrv,
first of all Thank you very much for writing this tutorial.
May I ask you for an extension.
I use DarkPlaces and use your tutorial for the bullets (not the one for the entities. I use Tux´s for that).
Now my question is:
The shotgun spawns 6 bullets and the supershotgun 14.
There is this line, that spreads them:
I tried to implement it into you "void ( vector org ) spawn_splash =" (by handling the numbers of bullets through the functions), but failed.
I have this:
vector org is your vector (the one you calculated the water surface with).
The result, by using the above code is, that the pointparticles are all spawned on the same spot
(so the spot gets overbright because of so many particles.)
I want to have the same visual as shooting on the wall (the 6 or 14 impact spots are spreaded (following the crandom()*spread line)).
Where is my mistake ?
Can you please help me ?
-----------
Another thing, that came into my mind:
When an entitiy is hitting water (or teleporter), you hear a "splash" sound --> "h2ohit1.wav"
But I cannot find the call for it.
So I guess it is hardcoded like the other sounds as well (example "dland2.wav").
Can I still cal this sound in my QC code or is it impossible cause it is an engine sound ?
I am sorry for my noob questions. I am still learning.
Thank you very much.
Regards,
Seven
first of all Thank you very much for writing this tutorial.
May I ask you for an extension.
I use DarkPlaces and use your tutorial for the bullets (not the one for the entities. I use Tux´s for that).
Now my question is:
The shotgun spawns 6 bullets and the supershotgun 14.
There is this line, that spreads them:
Code: Select all
direction = org + crandom()*0.04*v_right + crandom()*0.04*v_up;I have this:
Code: Select all
void (float shotcount, vector org) spawn_splash =
{
/*
local vector direction;
while (shotcount > 0)
{
direction = org + crandom()*2*v_right + crandom()*2*v_up;
pointparticles(particleeffectnum("watersplash"), direction, '0 0 0', 1);
shotcount = shotcount - 1;
}
};
The result, by using the above code is, that the pointparticles are all spawned on the same spot
(so the spot gets overbright because of so many particles.)
I want to have the same visual as shooting on the wall (the 6 or 14 impact spots are spreaded (following the crandom()*spread line)).
Where is my mistake ?
Can you please help me ?
-----------
Another thing, that came into my mind:
When an entitiy is hitting water (or teleporter), you hear a "splash" sound --> "h2ohit1.wav"
But I cannot find the call for it.
So I guess it is hardcoded like the other sounds as well (example "dland2.wav").
Can I still cal this sound in my QC code or is it impossible cause it is an engine sound ?
I am sorry for my noob questions. I am still learning.
Thank you very much.
Regards,
Seven
Re: Impacts in water using darkplaces
Update to my above post.
I realized what my mistake was... :roll:
Either I must use greater multipliers for "v_right" and "v_up" ("12" looks good),
or use standard vectors instead (like '5 -5 0'. Together with a good random routine)
But regarding the second question, I would be happy if someone could drop a line.
Thank you.
I realized what my mistake was... :roll:
Either I must use greater multipliers for "v_right" and "v_up" ("12" looks good),
or use standard vectors instead (like '5 -5 0'. Together with a good random routine)
But regarding the second question, I would be happy if someone could drop a line.
Thank you.
Re: Impacts in water using darkplaces
My code wasnt a tutorial, but I'm glad to hear people are finding a use for the mess I call code. 
In regards to bullet spread from the Shotguns, you could actually call W_BulletSpash from inside FireBullets instead, I guess.
Code from within the default FireBullets() function:
Now, I aint tested this, but you should be able to change that part to this:
You will have to move around W_BulletSplash in the files so its before FireBullets, or make a declaration for it before FireBullets, but this should ( in theory, note: not tested ) then actually run the W_BulletSplash for the exact location the bullets will hit, meaning you dont need to calculate the spread, as it's already done for you. This will give realistic positioning for the splash per bullet, not per shot as in my original idea.
In regards to question 2, yes, I *think* the call for the splash is engine side, but I've never looked thru the .qc for it, and haven't bothered to look before posting this either, heh. But you can the sound from QC no problem. All sounds in game can be called in QC, just use something akin to:
( That was taken directly from W_FireShotgun )
Things to change in it are the sound channel, idicated by CHAN_*, the attenuation ( i think thats what ATTN_ stands for ) part, ATTN_*, and obviously the path
to the sound you want to play, so the "weapons/guncock.wav".
So, to play the water splash in QC:
Maybe pick a more specific CHAN_* than CHAN_AUTO, but you get the idea.
EDIT:
If you do call W_BulletSplash from FireBullets(), anything else that uses FireBullets() would also get W_BulletSplash support instantly, for example, the Grunt / Soldier ( monster_army ).
I didnt really think this stuff when I knocked that up tho, as it's was just to demonstrate my method I spoke of before the code.
In regards to bullet spread from the Shotguns, you could actually call W_BulletSpash from inside FireBullets instead, I guess.
Code from within the default FireBullets() function:
Code: Select all
ClearMultiDamage ();
while (shotcount > 0)
{
direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up;
traceline (src, src + direction*2048, FALSE, self);
if (trace_fraction != 1.0)
TraceAttack (4, direction);
shotcount = shotcount - 1;
}
ApplyMultiDamage ();
Code: Select all
ClearMultiDamage ();
while (shotcount > 0)
{
direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up;
traceline (src, src + direction*2048, FALSE, self);
if (trace_fraction != 1.0)
TraceAttack (4, direction);
// QRV : Additional bit is here:
W_BulletSplash( direction );
shotcount = shotcount - 1;
}
ApplyMultiDamage ();
In regards to question 2, yes, I *think* the call for the splash is engine side, but I've never looked thru the .qc for it, and haven't bothered to look before posting this either, heh. But you can the sound from QC no problem. All sounds in game can be called in QC, just use something akin to:
Code: Select all
sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM);
Things to change in it are the sound channel, idicated by CHAN_*, the attenuation ( i think thats what ATTN_ stands for ) part, ATTN_*, and obviously the path
to the sound you want to play, so the "weapons/guncock.wav".
So, to play the water splash in QC:
Code: Select all
sound (self, CHAN_AUTO, "misc/h2ohit.wav", 1, ATTN_NORM);
EDIT:
If you do call W_BulletSplash from FireBullets(), anything else that uses FireBullets() would also get W_BulletSplash support instantly, for example, the Grunt / Soldier ( monster_army ).
I didnt really think this stuff when I knocked that up tho, as it's was just to demonstrate my method I spoke of before the code.
I'm looking for a Mapper, Modeller/Animator and a Sound effect/Music person, to work on an exciting project. PM Me here, or catch me on IRC for further info.
Re: Impacts in water using darkplaces
Hello Qrv,
Moving the call for W_BulletSpash into the loop of FireBullets() function worked.
That really saved a few lines of code, cause the random spread calculation must not be done twice.
Unfortunately the sound "h2ohit.wav" cannot be called from QC. It simply doesnt work (at least for me).
I had to duplicate it, rename it to whatever (i used "watersplash.wav") and then call it the usual way.
That worked.
In the end, I want to say: Thank you.
Your shotgun bullet code works flawlessly parallel to Tux´s entity watersplash code.
I could not hold off to post a small clip of both features (I hope you dont mind).
This is really an enhancement to Quake.
http://www.youtube.com/watch?v=_N-BEJJ7T30
Moving the call for W_BulletSpash into the loop of FireBullets() function worked.
That really saved a few lines of code, cause the random spread calculation must not be done twice.
Unfortunately the sound "h2ohit.wav" cannot be called from QC. It simply doesnt work (at least for me).
I had to duplicate it, rename it to whatever (i used "watersplash.wav") and then call it the usual way.
That worked.
In the end, I want to say: Thank you.
Your shotgun bullet code works flawlessly parallel to Tux´s entity watersplash code.
I could not hold off to post a small clip of both features (I hope you dont mind).
This is really an enhancement to Quake.
http://www.youtube.com/watch?v=_N-BEJJ7T30
Re: Impacts in water using darkplaces
Actually, I think I prob typo'd lol.
try h2ohit1.wav, or better yet, open the original iD pak's, and look in the sound folders yourself.
Also, after watching your video, what your splash needs is a ripple ring.
I dont have time now to look into making one myself, but you basically just need a square ripple texture, that aligns itself to the water, and have it scale its size up, so you get a fake ripple effect going on, if you know what I mean.
Dont forget to sling me some credits if you do use that mess of code, just a comment in the qc would be nice.
try h2ohit1.wav, or better yet, open the original iD pak's, and look in the sound folders yourself.
Also, after watching your video, what your splash needs is a ripple ring.
I dont have time now to look into making one myself, but you basically just need a square ripple texture, that aligns itself to the water, and have it scale its size up, so you get a fake ripple effect going on, if you know what I mean.
Dont forget to sling me some credits if you do use that mess of code, just a comment in the qc would be nice.
I'm looking for a Mapper, Modeller/Animator and a Sound effect/Music person, to work on an exciting project. PM Me here, or catch me on IRC for further info.
-
WickedShell
- Posts: 24
- Joined: Mon Feb 14, 2011 5:16 am
Re: Impacts in water using darkplaces
For shit's and giggles, I'd thought I'd add that all of those water splash entities could be done in CSQC to save the server from having to send out one as one entity, with just the origin, the baseline angle for the shot, and a seed for the random number generator. That makes it a single splash entity that gets networked once, rather then many entity's being added, keeps the load off the server, and since it's all pretty graphics effects, not gameplay there's no reason the server needs to know about it.
The seeded random number generator is optional, but nice because you can then have each bullet splash be at precisely where the bullet actually ended on the server, (because you can sync the seed values and calls to your RNG so that the same values pop out. The accuracy this offers you is probably not needed for a graphics effect, although it will be more noticeable if you have trail's from your projectiles.
If I'm missing something, lemme know (I've done CSQC work for maybe 2 days now), but I believe the theory is solid.
The seeded random number generator is optional, but nice because you can then have each bullet splash be at precisely where the bullet actually ended on the server, (because you can sync the seed values and calls to your RNG so that the same values pop out. The accuracy this offers you is probably not needed for a graphics effect, although it will be more noticeable if you have trail's from your projectiles.
If I'm missing something, lemme know (I've done CSQC work for maybe 2 days now), but I believe the theory is solid.
Re: Impacts in water using darkplaces
I've not looked into CSQC at all yet, but I've been reading bits about it here and there, from what I understand, yes, most of this splash effect could be moved to CSQC, and would indeed probably be better.
As I've not looked into CSQC much yet, if anyone could prehaps show a method of porting whats need of my code, over to CSQC, I'd be very grateful.
As I've not looked into CSQC much yet, if anyone could prehaps show a method of porting whats need of my code, over to CSQC, I'd be very grateful.
I'm looking for a Mapper, Modeller/Animator and a Sound effect/Music person, to work on an exciting project. PM Me here, or catch me on IRC for further info.