Weapon spread
by Krister Lindstr · in Torque Game Engine · 05/07/2002 (4:21 am) · 4 replies
We are doing a Tribes 2 mod as our 1 year final project for school, or rather we hope to do a Tribes 2 mod but we might have to change to another game engine, all depending on the some of the anwsers we may get here ;)
For example , we would like to modify the weapons aim, we simply want the aim to become worse and worse the longer you hold down the fire button, and also we want the starting aim to be better if you for example sit , and the aim to become a tad worse when moving etc.
Basicly we do know how to make something like it in c++, but what we need to know is how advanced the scripting is in Tribes 2, would it be possible to use simple programming in the scripts or are they so passive so that we only can change the existing paramiters?
We're Thankful for any tips or if you know of any documentation that may clear this up for us :)
For example , we would like to modify the weapons aim, we simply want the aim to become worse and worse the longer you hold down the fire button, and also we want the starting aim to be better if you for example sit , and the aim to become a tad worse when moving etc.
Basicly we do know how to make something like it in c++, but what we need to know is how advanced the scripting is in Tribes 2, would it be possible to use simple programming in the scripts or are they so passive so that we only can change the existing paramiters?
We're Thankful for any tips or if you know of any documentation that may clear this up for us :)
#2
I would work around it in a sloppy way.
create a bunch of projectiles with varying spread.
add an innaccuracy variable to each player.
create a recursive function that reduces player.innaccuracy for each player each second.
add a call to a calculate innaccuracy function in each firing sequence.
calculate innaccuracy sets player.innaccuracy to something like current velocity + 10 / last fire time.
then I'd put a switch in the fire function that picks which projectile to fire by the value of player.innaccuracy.
result:
10 times as many projectile data blocks as are necessary.
some stupid recursive global function that runs 100 times per second in a large multiplayer game.
the chaingun becomes less accurate if the player isn't standing still.
05/30/2002 (4:37 pm)
Krister, I think you are saying the problem is that the projectile data is not dynamic.I would work around it in a sloppy way.
create a bunch of projectiles with varying spread.
add an innaccuracy variable to each player.
create a recursive function that reduces player.innaccuracy for each player each second.
add a call to a calculate innaccuracy function in each firing sequence.
calculate innaccuracy sets player.innaccuracy to something like current velocity + 10 / last fire time.
then I'd put a switch in the fire function that picks which projectile to fire by the value of player.innaccuracy.
result:
10 times as many projectile data blocks as are necessary.
some stupid recursive global function that runs 100 times per second in a large multiplayer game.
the chaingun becomes less accurate if the player isn't standing still.
#3
What you do is modify the vector that the projectile will be fired on.
The chaingun for example already does this, what you need to do is change the way it is calculated:
For example in T2 projectiles.cs copy "ShapeBaseImageData::onFire" to "ChaingunImage::onFire"
We'll be working on the section between the following 2 lines:
Start - if(%data.projectileSpread)
End - if (isObject(%obj.lastProjectile) && %obj.deleteLastProjectile)
First we need to change that start line to this:
if(%obj.projectileSpread)
This changes the projectile Spread variable from being stored in the weaponImageDatablock to being stored on the player object.
Next we need to change all references to %data.projectileSpread to %obj.projectileSpread. There should be 3 lines to change right after the start line.
Once you've done that you need to add the code that increments the variance for each projectile fired. You'll need to do this twice. Once after each "%p = new (%data.projectileType)() {" block.
After the first one add this line:
%obj.projectileSpread = ((%obj.projectileSpread * 1000.0) + 0.1 ) / 1000.0;
After the second one add this:
%obj.projectileSpread = 0.1 / 1000.0;
The second one actually starts things off by setting up the initial spread variation, so the first shot will always be dead on. Each shot after that gets progressivly worse. Change the 0.1 to smaller or larger numbers to increase or decrease the rate of change.
After the changes that block of code should look like this:
To add in an additional variance for firing while moving you'll need to use the %obj.getVelocity() function.
Something like this:
Of course you'll need a way to reset the %obj.projectileSpread back to 0 when you stop firing.
For that I edited the weapons/chaingun.cs file.
In the ChaingunImage datablock you need to add a script variable into the spindown block:
And then you need to add that function:
05/30/2002 (8:31 pm)
It doesn't require any additional datablocks.What you do is modify the vector that the projectile will be fired on.
The chaingun for example already does this, what you need to do is change the way it is calculated:
For example in T2 projectiles.cs copy "ShapeBaseImageData::onFire" to "ChaingunImage::onFire"
We'll be working on the section between the following 2 lines:
Start - if(%data.projectileSpread)
End - if (isObject(%obj.lastProjectile) && %obj.deleteLastProjectile)
First we need to change that start line to this:
if(%obj.projectileSpread)
This changes the projectile Spread variable from being stored in the weaponImageDatablock to being stored on the player object.
Next we need to change all references to %data.projectileSpread to %obj.projectileSpread. There should be 3 lines to change right after the start line.
Once you've done that you need to add the code that increments the variance for each projectile fired. You'll need to do this twice. Once after each "%p = new (%data.projectileType)() {" block.
After the first one add this line:
%obj.projectileSpread = ((%obj.projectileSpread * 1000.0) + 0.1 ) / 1000.0;
After the second one add this:
%obj.projectileSpread = 0.1 / 1000.0;
The second one actually starts things off by setting up the initial spread variation, so the first shot will always be dead on. Each shot after that gets progressivly worse. Change the 0.1 to smaller or larger numbers to increase or decrease the rate of change.
After the changes that block of code should look like this:
if(%obj.projectileSpread)
{
%vector = %obj.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 (%data.projectileType)() {
dataBlock = %data.projectile;
initialDirection = %vector;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
vehicleObject = %vehicle;
};
%obj.projectileSpread = ((%obj.projectileSpread * 1000.0) + 0.1 ) / 1000.0;
}
else
{
%p = new (%data.projectileType)() {
dataBlock = %data.projectile;
initialDirection = %obj.getMuzzleVector(%slot);
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
vehicleObject = %vehicle;
};
%obj.projectileSpread = 0.1 / 1000.0;
}To add in an additional variance for firing while moving you'll need to use the %obj.getVelocity() function.
Something like this:
if(%obj.projectileSpread || %obj.getVelocity() !$= "0 0 0")
{
if (%obj.getVelocity !$= "0 0 0")
{
%moveSpread = 2.0 / 1000.0;
}
%vector = %obj.getMuzzleVector(%slot);
%x = (getRandom() - 0.5) * 2 * 3.1415926 * (%obj.projectileSpread + %moveSpread);
%y = (getRandom() - 0.5) * 2 * 3.1415926 * (%obj.projectileSpread + %moveSpread);
%z = (getRandom() - 0.5) * 2 * 3.1415926 * (%obj.projectileSpread + %moveSpread);
%mat = MatrixCreateFromEuler(%x @ " " @ %y @ " " @ %z);
%vector = MatrixMulVector(%mat, %vector);
%p = new (%data.projectileType)() {
dataBlock = %data.projectile;
initialDirection = %vector;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
vehicleObject = %vehicle;
};
%obj.projectileSpread = ((%obj.projectileSpread * 1000.0) + 0.1 ) / 1000.0;
}
else
{
%p = new (%data.projectileType)() {
dataBlock = %data.projectile;
initialDirection = %obj.getMuzzleVector(%slot);
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
vehicleObject = %vehicle;
};
%obj.projectileSpread = 0.1 / 1000.0;
}Of course you'll need a way to reset the %obj.projectileSpread back to 0 when you stop firing.
For that I edited the weapons/chaingun.cs file.
In the ChaingunImage datablock you need to add a script variable into the spindown block:
stateName[5] = "Spindown"; stateSound[5] = ChaingunSpinDownSound; stateSpinThread[5] = SpinDown; // stateTimeoutValue[5] = 1.0; stateWaitForTimeout[5] = true; stateScript[5] = "onSpindown"; // <-- Script variable stateTransitionOnTimeout[5] = "Ready"; stateTransitionOnTriggerDown[5] = "Spinup";
And then you need to add that function:
function ChaingunImage::onSpindown(%data, %obj, %slot) {
%obj.projectileSpread = 0;
}
#4
05/30/2002 (8:51 pm)
Methinks this needs to be a resource!
Torque Owner Badguy
what you need to do is open up one of the weapon scripts that tribes is using now
examine the variable's defined within the datablock for the weapon image so for example:
the variables found in there and then the corresponding function for that datablock
here you will find most of what it seems you want to do.
the script exposed is quite functional, and much can be done.
Goodluck,
but as is said here Why build a mod when you could build a game..
with tribes you wont be doing any c++ but you could with Torque :)