Game Development Community

Creating a Laser Projectile

by JD · in Torque 3D Professional · 07/14/2013 (5:16 am) · 21 replies

Ok I'm bringing it up! Laser Projectile, we need it!

This is what I'm working on but I'm not sure what to edit that could make it work correctly:

datablock ProjectileData(KralmokProjectile)
{
projectileShapeName = "art/shapes/weapons/SwarmGun/rocket.dts";
directDamage = 100;
radiusDamage = 0;
damageRadius = 0;
areaImpulse = 2500;

explosion = RocketLauncherExplosion;
waterExplosion = RocketLauncherWaterExplosion;

decal = ScorchRXDecal;
splash = RocketSplash;

particleEmitter = Laser1TrailEmitter;
particleWaterEmitter = RocketTrailWaterEmitter;

muzzleVelocity = 100;
velInheritFactor = 0.3;

armingDelay = 0;
lifetime = 5000; //(500m / 100m/s = 5000ms)
fadeDelay = 4500;

bounceElasticity = 0;
bounceFriction = 0;
isBallistic = false;
gravityMod = 0.80;

lightDesc = KralmokLightDesc;

damageType = "RocketDamage";
};

datablock LightDescription(KralmokLightDesc)
{
range = 50.0;
color = "2 3 3";
brightness = 15.0;
animationType = PulseLightAnim;
animationPeriod = 8.25;
//flareType = SimpleLightFlare0;
};

datablock ParticleData(Laser1Trail)
{
textureName = "art/shapes/particles/beam_blue";
dragCoeffiecient = 0;
gravityCoefficient = -0.202686;
inheritedVelFactor = 0.0;
constantAcceleration = 0.0;
lifetimeMS = 750;
lifetimeVarianceMS = 749;
useInvAlpha = true;
spinRandomMin = -60;
spinRandomMax = 0;
spinSpeed = 1;

colors[0] = "0.3 0.3 0.3 0.598425";
colors[1] = "0.9 0.9 0.9 0.897638";
colors[2] = "0.9 0.9 0.9 0";

sizes[0] = 0.247207;
sizes[1] = 0.497467;
sizes[2] = 0.747726;

times[0] = 0.0;
times[1] = 0.4;
times[2] = 1.0;
animTexName = "art/shapes/particles/beam_blue";
times[3] = "1";
};

datablock ParticleEmitterData(Laser1TrailEmitter)
{
ejectionPeriodMS = 1;
periodVarianceMS = 0;
ejectionVelocity = 0.75;
velocityVariance = 0;
thetaMin = 0.0;
thetaMax = 0.0;
phiReferenceVel = 90;
phiVariance = 0;
particles = "Laser1Trail";
};
datablock ParticleData(Laser1TrailParticle)
{
textureName = "art/shapes/particles/impact";
dragCoeffiecient = 0;
inheritedVelFactor = 0.0;
constantAcceleration = 0.0;
lifetimeMS = 1200;//1000;
lifetimeVarianceMS = 299;//500;
useInvAlpha = true;//false;
spinSpeed = 1;
spinRandomMin = -300.0;
spinRandomMax = 0;
colors[0] = "1 0.897638 0.795276 0.4";
colors[1] = "0.795276 0.795276 0.795276 0.6";
colors[2] = "0 0 0 0";
sizes[0] = 0.5;//1.0;
sizes[1] = 2;
sizes[2] = 1;//1.0;
times[0] = 0.0;
times[1] = 0.498039;
times[2] = 1.0;
animTexName = "art/shapes/particles/impact";
times[3] = "1";
};

About the author

Check out my website: http://lethonline.com/ *a home for all gamers!*

Page «Previous 1 2
#1
07/14/2013 (8:52 am)
Have you thought about attaching an staticshape object to muzzlepoint to show the "beam" and using a raycast for the actual hit detection?
#2
07/14/2013 (9:05 am)
For a short laser burst couldn't you just stretch out the projectile and add a red or green glow?

Less of a cost to raycasts?
#3
07/14/2013 (1:02 pm)
Recently tacked on a bit of additional utility to:

http://www.garagegames.com/community/resource/view/8006/7#comments

this end. Works pretty well.
#4
07/14/2013 (2:22 pm)
Quote:Less of a cost to raycasts?
Not sure what you mean, but the Projectile class uses a raycast every tick to move itself.
#5
07/14/2013 (3:22 pm)
Wasn't there an old LaserProjectile resource out there? I'm sure with some work you could get it into T3D.

I might have a look at it myself as my next project calls for a laser projectile.
#6
07/14/2013 (5:45 pm)
I'd appreciate it man... also I had asked a question about your php master server...

https://www.garagegames.com/community/resources/view/21921/1#comment-192875
#7
07/15/2013 (4:30 am)
@Daniel - I meant, no point having more than one raycast, one for the projectile and one for hit detection.

I guess it depends how long you want the beam also, using a standard projectile (star wars gun wise you could just modify the projectile shape).
#8
07/15/2013 (6:21 am)
I've always preferred the point-to-point "flicker" of a beam more like Star Trek over the Star Wars variety - light moves pretty fast....

On that note, a single ray cast and then do like Steve mentions - attach on end to the barrel and stretch the shape to touch the target, flicker the visibility, spawn the hit particles and call it.

Hmm. Now I want to experiment with this myself.
#10
07/15/2013 (9:16 am)
These are nice laserguns Steve, might use something similar for some magic spells in my game.
#11
07/15/2013 (10:15 am)
Aw yeah, that looks sweet....
#12
07/15/2013 (12:15 pm)
@James,
Are you looking for a plasma weapon (short burst of elongated plasma energy), continuous beam weapon (like what Steve has done), or an invisible/semi-invisible beam (more like a real laser)? BTW lasers are not visible unless they are hitting dust or a wall. Now IR lasers you cannot see at all.

This would be like a plasma bolt:
demolishun.net/images/plasmaboltbuggone.jpg
Here are a couple of more, but with mipmapping issues that had to do with exporting to DTS from Blender:
demolishun.net/images/distance_view_bug1.jpgdemolishun.net/images/distance_view_bug2.jpg
The plasma bolt is just a projectile that is make from two quads at 90 deg in a cross pattern (x pattern might look better). Then I use 2 white textures that have the plasma in the middle and just add color and light to the projectile. So any color you want. I was looking to make SW style plasma bolts. Not really lasers at all.

All of these pictures are from TGE btw.
#13
07/15/2013 (2:54 pm)
Well I'm actually looking for a little bit of both of what you and steve have, I have a alien rocket launcher. I'd rather the projectile be what steve did on that second weapon-a big red beam. However for some of the pistols I'd like short burst as is what you've shown me... Can y'all please show me some scripts for this-and w/e files you had to add into T3D?

BTW steve, I kind of hate you for even showing me that but not showing me how =P
#14
07/15/2013 (8:45 pm)
@James,
I don't think I have the scripts for that anymore. It was for TGE and when I was running Linux most of the time. It was not particularly difficult though. Mostly it was figuring out the right Blender export settings. Also, they are not particle effects. That would have to be added. I think adding a trailing particle would look nice though. My favorite is the light it casts on the ground. I am not entirely sure the scripting would be the same for T3D.
#15
07/15/2013 (10:29 pm)
hmmm-do you remember the areas you modified? Steve you gotta give that up man, that's not fair! :( That's gorgeous beams man!
#16
07/15/2013 (10:58 pm)
Yeah, sort of. It was a cross pattern rectangle. The cross is at the end like an x. It was just textured with a elongated pill shaped object with some alpha so it could be semi transparent. Then I added light (somehow) and colored it red. There really is almost nothing to it.
#17
07/15/2013 (11:45 pm)
I'm pretty sure you can just mount lights to Projectiles. Here's an old example from T3D 1.1 or something. I imagine it would be kind of the same now:
function BoomGlove::onFire(%this, %obj, %slot)
{
   %pos = %obj.getMuzzlePoint(%slot);
   %dir = %obj.getMuzzleVector(%slot);
   %data = BoomRocket;
   %p = new Projectile() {
      datablock = %data;
      initialPosition = %pos;
      initialVelocity = VectorScale(%dir, %data.speed);
      sourceObject = %obj;
      team = "hate";//%obj.team;
   };
   %l = new PointLight() {
      color = "1 1 1 1";
      radius = 50;
      flareType = SunFlareExample3;
      flareScale = 0.4;
   };
   %p.mountObject(%l, 0);
   %p.light = %l;
}

function BoomRocket::onExplode(%this, %obj, %pos, %fade)
{
   radiusDamage(%obj, %obj.getPosition(),
      %this.damageRadius, %this.damage, "boom",
      %this.impulse, %obj.team);
   if(isObject(%obj.light))
      %obj.light.delete();
}
BoomGlove is the name of the weapon image, and BoomRocket is the name of the projectile datablock. Oh and as a bonus, this script includes a flare on the light (not sure if the same flare datablock still exists by default though), which looked really sexy. You'll want to just pick out the stuff relating to the light, though - this script doesn't use the stock weapon image scripts from the Full template.

As far as I can tell from what Steve has told us, his beams are basically a static shape mounted to the weapon image and scaled. So you'd do a raycast and get the hit distance, attach your shape, set its y scale to whatever the distance was, then schedule a deletion (or manage that via the weapon image state system, whatever your preference).
#18
07/16/2013 (7:39 am)
Demolishun's plasma bolt I call them photons - but each to their own!) are easy enough, just make the model shape, have the texture nice and bright and set the material to emissive with alphaRef.

i.imgur.com/ZMVtWK4.jpg
Real simple, 4tris/2polys. It's what I use for tracer/bullets. I favour a front facing poly so you can see them coming at you.
#19
07/16/2013 (8:53 am)
Does anyone remember that projectiles can be animated... for extra plasma gooey-ness :)
#20
07/16/2013 (8:58 am)
Also, Plastic Gem #29: Zapper Lightning demonstrates how to attach/stretch a StaticShape for a beam type device -- in this case a lightning bolt.
Page «Previous 1 2