How to add projectile spread?
by Karsten "Clocks" Viese · in Torque Game Engine · 10/20/2001 (10:30 am) · 8 replies
I copied this from a T2 weapon script to see if it by any change would work.
But since the TGE has its own brand new projectile system I was almost certain that it wouldn't work.
This is the snipit I added.
projectileSpread = 8.0 / 1000.0;
And sure enough this didn't work.
I put it in the same place as it was in the T2 weapon script.
So is there anyway to make the bullets spread over distance in TGE using the projectile system.
// Clocks out.
But since the TGE has its own brand new projectile system I was almost certain that it wouldn't work.
This is the snipit I added.
projectileSpread = 8.0 / 1000.0;
And sure enough this didn't work.
I put it in the same place as it was in the T2 weapon script.
So is there anyway to make the bullets spread over distance in TGE using the projectile system.
// Clocks out.
About the author
#2
10/20/2001 (11:44 am)
... if someone actually does something like this, and it works :), we should get it posted as a resource "HowTo" and add it to the Torque scripting section of the resource tree.
#3
Create the projectile object
in the rifle.cs
But it don't seem to have any effect.
I also up'ed this:
%deviation = getRandom(0.1);
To
%deviation = getRandom(5.0);
To see if the first was to low to notice.
Maybe someone could look into this :)
// Clocks out.
10/20/2001 (1:01 pm)
I added it right before:Create the projectile object
in the rifle.cs
But it don't seem to have any effect.
I also up'ed this:
%deviation = getRandom(0.1);
To
%deviation = getRandom(5.0);
To see if the first was to low to notice.
Maybe someone could look into this :)
// Clocks out.
#4
// Random deviation from center line, this value basically
// controls the spread.
%deviation = getRandom(0.1);
// Random rotation around muzzle vector axis
%rotation = "0 0 0" SPC %muzzleVector SPC %getRandom(360);
// Build the offset vector which will be perpendiculer
// to the muzzle vector. This assumes you can never
// look exactly straight up or down.
%offset = VectorCross("0 0 1",%muzzleVector);
%offset = VectorNormalize(%offset);
%offset = VectorScale(%offset,%deviation);
%offset = MatrixMulVector(%rotation,%offset);
// Add it to the initial velocity
%velocity = VectorAdd(%velocity,%offset);
Being the non-programmer that I am, I can't find it :(
// Clocks out.
10/20/2001 (1:21 pm)
The console tells me there's a syntax error in this line:// Random deviation from center line, this value basically
// controls the spread.
%deviation = getRandom(0.1);
// Random rotation around muzzle vector axis
%rotation = "0 0 0" SPC %muzzleVector SPC %getRandom(360);
// Build the offset vector which will be perpendiculer
// to the muzzle vector. This assumes you can never
// look exactly straight up or down.
%offset = VectorCross("0 0 1",%muzzleVector);
%offset = VectorNormalize(%offset);
%offset = VectorScale(%offset,%deviation);
%offset = MatrixMulVector(%rotation,%offset);
// Add it to the initial velocity
%velocity = VectorAdd(%velocity,%offset);
Being the non-programmer that I am, I can't find it :(
// Clocks out.
#5
What you will need to do is this...
// Create the projectile object
%p = new (%this.projectileType)() {
dataBlock = %projectile;
initialVelocity = %velocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
This bit of code is going to have to be changed to create more then 1 projectile because as it is now it just creates 1 bullet.. How to fix this you say.
Try the following.
%vector = %this.getMuzzleVector(%slot);
%x = (getRandom() - 0.5) * 2 * 3.1415926 * %obj.projectileSpread;
%y = (getRandom() - 0.5) * 2 * 3.1415926 * %obj.projectileSpread;
%z = (getRandom() - 0.5) * 2 * 3.1415926 * %obj.projectileSpread;
%mat = MatrixCreateFromEuler(%x @ " " @ %y @ " " @ %z);
%vector = MatrixMulVector(%mat, %vector);
%p = new (%this.projectileType)() {
dataBlock = %projectile;
initialDirection = %vector;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
(Please note I did not test this.. You may need to add the projectileSpread into a projectileSpread datablock.. Or possibly create a sub script that does the same or similar work as that of what the datablock should do.)
I'll do some testing and get it to working. and post what I find..
10/20/2001 (1:31 pm)
Well its not just that easy.. :)What you will need to do is this...
// Create the projectile object
%p = new (%this.projectileType)() {
dataBlock = %projectile;
initialVelocity = %velocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
This bit of code is going to have to be changed to create more then 1 projectile because as it is now it just creates 1 bullet.. How to fix this you say.
Try the following.
%vector = %this.getMuzzleVector(%slot);
%x = (getRandom() - 0.5) * 2 * 3.1415926 * %obj.projectileSpread;
%y = (getRandom() - 0.5) * 2 * 3.1415926 * %obj.projectileSpread;
%z = (getRandom() - 0.5) * 2 * 3.1415926 * %obj.projectileSpread;
%mat = MatrixCreateFromEuler(%x @ " " @ %y @ " " @ %z);
%vector = MatrixMulVector(%mat, %vector);
%p = new (%this.projectileType)() {
dataBlock = %projectile;
initialDirection = %vector;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
(Please note I did not test this.. You may need to add the projectileSpread into a projectileSpread datablock.. Or possibly create a sub script that does the same or similar work as that of what the datablock should do.)
I'll do some testing and get it to working. and post what I find..
#7
%rotation = "0 0 0" SPC %muzzleVector SPC getRandom(360);
I removed the % in front of getRandom(360)
10/21/2001 (3:11 pm)
The line should read:%rotation = "0 0 0" SPC %muzzleVector SPC getRandom(360);
I removed the % in front of getRandom(360)
#8
Did I put it in the right place?
This is somewhat important as the weapons are too accurate as it is now.
I can hit someone with one shot from as far as the fog allow me to see. And that's just not fun in the long run.
// Clocks out
10/21/2001 (3:33 pm)
That still don't work.Did I put it in the right place?
This is somewhat important as the weapons are too accurate as it is now.
I can hit someone with one shot from as far as the fog allow me to see. And that's just not fun in the long run.
// Clocks out
Torque Owner Tim Gift
This seems like a bit of script work... but my first idea would be to add something like this to the projectile's onFire script:
// Random deviation from center line, this value basically // controls the spread. %deviation = getRandom(0.1); // Random rotation around muzzle vector axis %rotation = "0 0 0" SPC %muzzleVector SPC getRandom(360); // Build the offset vector which will be perpendiculer // to the muzzle vector. This assumes you can never // look exactly straight up or down. %offset = VectorCross("0 0 1",%muzzleVector); %offset = VectorNormalize(%offset); %offset = VectorScale(%offset,%deviation); %offset = MatrixMulVector(%rotation,%offset); // Add it to the initial velocity %velocity = VectorAdd(%velocity,%offset);This is just an idea of one way to do it, I haven't tested this code. Maybe someone has something better? :)