Different Explosion when projectile hits a player object.
by Michael Cozzolino · 06/28/2002 (10:52 am) · 37 comments
****Updated 5/25/04****
***********************
Create all the explosion data that you need for your explosion and create a projectile DataBlock in a seperate .cs. (Don't forget to have it execute !!!)
In the projectile DataBlock it seems important to set these values to this to work well:
muzzleVelocity = 1;
armingDelay = 0;
lifetime = 500;
explosion = "Your blood explosion that you made";
particleEmitter = Your blood emitter that looks like your explosion;
//Note If you want to use the decal for a blood splatter like Sabrecyd metions further down in this thread you will probably want to have the lifetime fairly high say 10000. The reason being that when the player hit with a kill shot the 2nd projectile will not have the player's collision box to collide with so the projectile won't explode until it hits the ground or a wall or something then the decal will appear and if the liftime is too low the projectile will just disappear before it collides with anything.
Also it should be noted that because of the kill shot problem I advise that you create a projectile emitter that looks like the blood explosion so you have a blood explosion effect to deal with the problem above. I won't go into the creation of this too much because you will need to tweak it to get the effect you are looking for. I will give you my emitter datablock as a guide you may want to use. Read the comments so you know why I set the data the way I did.
datablock ParticleData(BulletPlayerImpactSmokeParticle)
{
dragCoefficient = 0.0;
gravityCoefficient = 0.7; // makes the particles fall fairly fast illusion of drip
inheritedVelFactor = 0.0;
constantAcceleration = 0.0;
lifetimeMS = 300; // short don't need blood gush forever
lifetimeVarianceMS = 50;
useInvAlpha = true;
spinRandomMin = -90.0;
spinRandomMax = 90.0;
textureName = "~/data/shapes/particles/bulletsmoke";
colors[0] = "0.5 0.0 0.0 0.0"; // This goes Red, Green , Blue, Alpha
colors[1] = "0.5 0.0 0.0 0.4";
colors[2] = "0.5 0.0 0.0 0.0";
sizes[0] = 0.5; //Kept the size fairly small. Make it big if it's a rocket :)
sizes[1] = 0.5;
sizes[2] = 1.2;
times[0] = 0.0;
times[1] = 0.5;
times[2] = 1.0;
};
datablock ParticleEmitterData(BulletPlayerImpactSmoke)
{
ejectionPeriodMS = 50;
periodVarianceMS = 1;
ejectionVelocity = 1.0;
velocityVariance = 0.5;
ejectionOffset = 0.0;
thetaMin = 0;
thetaMax = 35;
overrideAdvances = false;
particles = "BulletPlayerImpactSmokeParticle";
lifetimeMS = 350; // Again no need to keep it going forever
};
On to the functions.
I put this in my rifle .cs file but you could probably put it in any server .cs
function blood(%pos)
{
%n = new Projectile() {
dataBlock = BloodProjectile;
initialPosition = %pos;
};
MissionCleanup.add(%n);
}
Your weapons onCollision function should look like this along with any thing else you are doing in there.
function RifleProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
// Apply damage to the object all shape base objects
if (%col.getType() & $TypeMasks::ShapeBaseObjectType)
%col.damage(%obj,%pos,%this.directDamage,"RifleBullet");
if (%col.getclassName() $= "player") {
blood(%obj.position);
}
}
***********************
Create all the explosion data that you need for your explosion and create a projectile DataBlock in a seperate .cs. (Don't forget to have it execute !!!)
In the projectile DataBlock it seems important to set these values to this to work well:
muzzleVelocity = 1;
armingDelay = 0;
lifetime = 500;
explosion = "Your blood explosion that you made";
particleEmitter = Your blood emitter that looks like your explosion;
//Note If you want to use the decal for a blood splatter like Sabrecyd metions further down in this thread you will probably want to have the lifetime fairly high say 10000. The reason being that when the player hit with a kill shot the 2nd projectile will not have the player's collision box to collide with so the projectile won't explode until it hits the ground or a wall or something then the decal will appear and if the liftime is too low the projectile will just disappear before it collides with anything.
Also it should be noted that because of the kill shot problem I advise that you create a projectile emitter that looks like the blood explosion so you have a blood explosion effect to deal with the problem above. I won't go into the creation of this too much because you will need to tweak it to get the effect you are looking for. I will give you my emitter datablock as a guide you may want to use. Read the comments so you know why I set the data the way I did.
datablock ParticleData(BulletPlayerImpactSmokeParticle)
{
dragCoefficient = 0.0;
gravityCoefficient = 0.7; // makes the particles fall fairly fast illusion of drip
inheritedVelFactor = 0.0;
constantAcceleration = 0.0;
lifetimeMS = 300; // short don't need blood gush forever
lifetimeVarianceMS = 50;
useInvAlpha = true;
spinRandomMin = -90.0;
spinRandomMax = 90.0;
textureName = "~/data/shapes/particles/bulletsmoke";
colors[0] = "0.5 0.0 0.0 0.0"; // This goes Red, Green , Blue, Alpha
colors[1] = "0.5 0.0 0.0 0.4";
colors[2] = "0.5 0.0 0.0 0.0";
sizes[0] = 0.5; //Kept the size fairly small. Make it big if it's a rocket :)
sizes[1] = 0.5;
sizes[2] = 1.2;
times[0] = 0.0;
times[1] = 0.5;
times[2] = 1.0;
};
datablock ParticleEmitterData(BulletPlayerImpactSmoke)
{
ejectionPeriodMS = 50;
periodVarianceMS = 1;
ejectionVelocity = 1.0;
velocityVariance = 0.5;
ejectionOffset = 0.0;
thetaMin = 0;
thetaMax = 35;
overrideAdvances = false;
particles = "BulletPlayerImpactSmokeParticle";
lifetimeMS = 350; // Again no need to keep it going forever
};
On to the functions.
I put this in my rifle .cs file but you could probably put it in any server .cs
function blood(%pos)
{
%n = new Projectile() {
dataBlock = BloodProjectile;
initialPosition = %pos;
};
MissionCleanup.add(%n);
}
Your weapons onCollision function should look like this along with any thing else you are doing in there.
function RifleProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
// Apply damage to the object all shape base objects
if (%col.getType() & $TypeMasks::ShapeBaseObjectType)
%col.damage(%obj,%pos,%this.directDamage,"RifleBullet");
if (%col.getclassName() $= "player") {
blood(%obj.position);
}
}
About the author
Indie Developer in the Albany NY area. iOS, PC, Mac OSX development. http://itunes.apple.com/us/artist/michael-cozzolino/id367780489
#2
This appears to work great server side, but doesn't work with a client connection. Any ideas?
-Sabrecyd
07/08/2002 (5:11 am)
Michael,This appears to work great server side, but doesn't work with a client connection. Any ideas?
-Sabrecyd
#3
07/08/2002 (7:24 am)
hmmm. I did not test this out with a client connection but I saw no need. I'm not sure what the problem is. I will look into it. I caught this post on my way to go fishing. I will try it out tomorrow. BTW did you get any explosion when you the player is hit when you are using a client connection or do you get the default explosion or do you get the "blood" explosion as a default?
#4
I think if I uncomment the explosion in the datablock, the server connection uses the blood explosion (must override datablock) and the client will then use the default explosion in the datablock, but not the blood explosion.
Hope that wasn't too confusing.
07/09/2002 (5:13 am)
When I use a client connection I don't get an explosion at all. It appears that it wants to use the one defined in the ProjectileData datablock, but that one is commented out so it doesn't use any :( A server connection works fine this way though.I think if I uncomment the explosion in the datablock, the server connection uses the blood explosion (must override datablock) and the client will then use the default explosion in the datablock, but not the blood explosion.
Hope that wasn't too confusing.
#5
07/10/2002 (8:46 am)
As soon as you mentioned that it didn't work client side I figured that is what was happening. I'm trying to figure out another way to make this work. I'll keep you posted here if I can make any progress.
#6
Instead of adding an explosion I added a projectile to the scene on collision with a player.
Here is what I need you to do.
Create all the explosion data that you need for your explosion and create a projectile DataBlock in a seperate .cs. (Don't forget to have it exec !!!)
In the projectile DataBlock it seems important to set these values to this to work well:
muzzleVelocity = 1;
armingDelay = 0;
lifetime = 500;
explodeOnDeath = true; // Not sure if you need this
On to the functions.
I put this in my rifle .cs file but you could probably put it in any server .cs
function blood(%pos)
{
%n = new Projectile() {
dataBlock = BloodProjectile;
initialPosition = %pos;
};
MissionCleanup.add(%n);
}
Your weapons onCollision function should look like this along with any thing else you are doing in there.
function RifleProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
// Apply damage to the object all shape base objects
if (%col.getType() & $TypeMasks::ShapeBaseObjectType)
%col.damage(%obj,%pos,%this.directDamage,"RifleBullet");
if (%col.getclassName() $= "player") {
blood(%obj.position);
}
}
That's it. I hope you get a chance to see if this works. Let me know how it goes.
Mike Cozzolino
08/09/2002 (7:45 am)
Will you try this? With a dedicated server and we can see if it works.Instead of adding an explosion I added a projectile to the scene on collision with a player.
Here is what I need you to do.
Create all the explosion data that you need for your explosion and create a projectile DataBlock in a seperate .cs. (Don't forget to have it exec !!!)
In the projectile DataBlock it seems important to set these values to this to work well:
muzzleVelocity = 1;
armingDelay = 0;
lifetime = 500;
explodeOnDeath = true; // Not sure if you need this
On to the functions.
I put this in my rifle .cs file but you could probably put it in any server .cs
function blood(%pos)
{
%n = new Projectile() {
dataBlock = BloodProjectile;
initialPosition = %pos;
};
MissionCleanup.add(%n);
}
Your weapons onCollision function should look like this along with any thing else you are doing in there.
function RifleProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
// Apply damage to the object all shape base objects
if (%col.getType() & $TypeMasks::ShapeBaseObjectType)
%col.damage(%obj,%pos,%this.directDamage,"RifleBullet");
if (%col.getclassName() $= "player") {
blood(%obj.position);
}
}
That's it. I hope you get a chance to see if this works. Let me know how it goes.
Mike Cozzolino
#7
Yeah, I'll give this a try. I was on vacation for a few days. Looks like I have a lot of stuff to try and catch up on.
-Sabrecyd
08/13/2002 (5:33 am)
Hey Mike,Yeah, I'll give this a try. I was on vacation for a few days. Looks like I have a lot of stuff to try and catch up on.
-Sabrecyd
#8
08/13/2002 (9:12 am)
This doesnt work in the clients because you are doing it from a server side script! Of course it wont work on clients. You have 2 options... either send a commandToClient that will render the new explosion, or either edit the projectile.cc code to do it instead. It will be much easier to do it in the engine i code... i did something like this... but beware... it wont look realistic, because the explosions will get created where the projectile collides, and the projectile collides against the bounds box... not the mesh... so blood will look like it's coming out from the air and not the player... but if it's ok with you go ahead and try.
#9
08/13/2002 (9:27 am)
Xavier are you commenting on the original code or the change I made below?
#10
08/14/2002 (6:59 am)
Mike, I had a bit of a meltdown last night and need to completely reformat my computer and reinstall everything. Sometimes I really hate Microsoft. I'll still give this a try when I can, but I'm sure Xavier is right. I have some other "spawned" explosion type things like you're doing above and those work fine server side, but not client. If I find out different when I get set back up I'll be sure to post it here.
#11
In my code i'm spawning a projectile instead of just creating and spawning an explosion.
If I get a chance I will try and get my server up to test. I have been busy lately because I'm in the process of moving.
08/14/2002 (11:06 am)
This is the reason I think this might work. This was a quote form Tim Gift in a Torque Bug thread about spawning explosions causing a dedicated server crash.Quote:Explosions are created indirectly on the client by other networked objects, such as the projectile, vehicles, etc.
In my code i'm spawning a projectile instead of just creating and spawning an explosion.
If I get a chance I will try and get my server up to test. I have been busy lately because I'm in the process of moving.
#12
08/14/2002 (11:26 am)
Mike, I'll try this out tonight using a different computer and my laptop. The computer that crashed on me might be down for awhile. I think the stuff I've tried before were all new explosions now that I think about it, so hopefully adding a new projectile will work :)
#13
08/14/2002 (12:10 pm)
Well I just tested it and it works. No crashes, and it works.
#14
I'll still try it out tonight after I kick that POS computer out of my way :)
08/14/2002 (12:23 pm)
Hey cool. Nice job. I'll still try it out tonight after I kick that POS computer out of my way :)
#15
I will update this resource probably by tomorrow. I have to got to work now :(
08/14/2002 (1:07 pm)
Although this works great I just tweaked my particleEmitter settings to make it look better as far as blood spraying is concerned because for instance when I get a headshot with my sniper rifle the player dies and the second projectile has nothing to collide with so by making an emmiter that looks alot like my explosion i'm able to get around this.I will update this resource probably by tomorrow. I have to got to work now :(
#16
Just a thought, but I wonder if this could be combined with the decal code stuff. When that second projectile (or maybe even a 3rd after collision) hits the player a new projectile could be created at that location and hit what ever is close behind the player leaving a "blood splat" decal. Might work because the decal is set in the projectile datablock.
08/14/2002 (1:22 pm)
That's cool.Just a thought, but I wonder if this could be combined with the decal code stuff. When that second projectile (or maybe even a 3rd after collision) hits the player a new projectile could be created at that location and hit what ever is close behind the player leaving a "blood splat" decal. Might work because the decal is set in the projectile datablock.
#17
btw the decal stuff works fine with it too. The projectile I spawned at the player leaves a blood splat decal if it hits a surface - sweet.
08/15/2002 (5:03 am)
You're right on here Mike! I tried it out last night finally. Works client side and there's no crash issues. I see what you mean about the emitter. It looked kinda funky using the basic bullet emitter I had at first. The gravity and some other settings can be tweaked to make it a little better.btw the decal stuff works fine with it too. The projectile I spawned at the player leaves a blood splat decal if it hits a surface - sweet.
#18
08/15/2002 (5:55 am)
Great to hear that. I may have to implement the decal stuff to see. It sounds like it would be pretty cool.
#19
08/15/2002 (8:19 am)
As of 8/15/02 This resource now works both server and client side so disregard the comments in the thread that say otherwise.
#20
08/15/2002 (9:45 am)
It's very nasty to do it this way... but well if you still like it that way disregard my comments, but it's stupid to create another projectile just for another explosion.
Torque Owner Sabrecyd
Using the onCollision and TypeMask should work for other effects too. terrain vs structure etc.