SideWinder Projectiles
by Kirchgessner · 02/20/2009 (6:49 am) · 14 comments
Ok we need to start out by editing the source files you'll need.
projectile.cc (ccp if TGEA)
projectiles.h
The code to add to your Datablock. I used the crossbow and increased the life of the particles so the effect would be a little more apparent.
Next we need to start editing the source code.
Lets start with projectile.h near line 55 where the ballistic code is defined.
Next we move on to the main projectiles.cc or ccp file.
We need to start out around line 68.
Scroll down to the initPersistFields() section. And call the settings.
Now move down again to the packData
Ok Now for the final and last part of it all. This is where the magic happens.
Move down to the processTick
A bug was found on compiling for TGE the fix is below this entry
-TGE 1.5 This was found by Scooby
I appreciate your help with this.
Here is what you get from the final product.
projectile.cc (ccp if TGEA)
projectiles.h
The code to add to your Datablock. I used the crossbow and increased the life of the particles so the effect would be a little more apparent.
datablock ProjectileData(CrossbowProjectile)
{
...
//Sidewinder Projectile code
isSidewinder = true;
crazyness = 500;
sideDelay = 300;
multiplier = 27;
...
}Next we need to start editing the source code.
Lets start with projectile.h near line 55 where the ballistic code is defined.
class ProjectileData : public GameBaseData
{
...
/// Should it arc?
bool isBallistic;
+ //Sidewinder Stuff
+ bool isSidewinder;
+ F32 crazyness; //This effects the random number generator
+ S32 sideDelay; //Delay control
+ F32 multiplier; //Controls the intensity
...
}Next we move on to the main projectiles.cc or ccp file.
We need to start out around line 68.
ProjectileData::ProjectileData()
{
...
isBallistic = false;
velInheritFactor = 1.0f;
muzzleVelocity = 50;
+ isSidewinder = false;
+ crazyness = 1000; //BSK 1000 less 10 more
+ sideDelay = 10;
+ multiplier = 25;
...
}Scroll down to the initPersistFields() section. And call the settings.
void ProjectileData::initPersistFields()
{
...
addNamedField(isBallistic, TypeBool, ProjectileData);
addNamedFieldV(velInheritFactor, TypeF32, ProjectileData, new FRangeValidator(0, 1));
addNamedFieldV(muzzleVelocity, TypeF32, ProjectileData, new FRangeValidator(0, 10000));
+ //Sidewinder stuff
+ addNamedField(isSidewinder, TypeBool, ProjectileData);
+ addNamedFieldV(crazyness, TypeF32, ProjectileData, new FRangeValidator(0, 500));
+ addNamedFieldV(sideDelay, TypeS32, ProjectileData, new IRangeValidatorScaled(TickMs, 0, Projectile::MaxLivingTicks));
+ addNamedFieldV(multiplier, TypeF32, ProjectileData, new FRangeValidator(0, 500));
...
}Now move down again to the packData
void ProjectileData::packData(BitStream* stream)
{
Parent::packData(stream);
...
if(stream->writeFlag(isBallistic))
{
stream->write(gravityMod);
stream->write(bounceElasticity);
stream->write(bounceFriction);
}
+ //Sidewinder stuff
+ if(stream->writeFlag(isSidewinder)){
+ stream->write(crazyness);
+ stream->write(sideDelay);
+ }
}
void ProjectileData::unpackData(BitStream* stream)
{
Parent::unpackData(stream);
...
isBallistic = stream->readFlag();
if(isBallistic)
{
stream->read(&gravityMod);
stream->read(&bounceElasticity);
stream->read(&bounceFriction);
}
+ //Sidewinder Stuff
+ isSidewinder = stream->readFlag();
+ if(isSidewinder){
+ stream->read(&crazyness);
+ stream->read(&sideDelay);
+ }
}Ok Now for the final and last part of it all. This is where the magic happens.
Move down to the processTick
A bug was found on compiling for TGE the fix is below this entry
void Projectile::processTick(const Move* move)
{
Parent::processTick(move);
...
oldPosition = mCurrPosition;
if(mDataBlock->isBallistic)
mCurrVelocity.z -= 9.81 * mDataBlock->gravityMod * (F32(TickMs) / 1000.0f);
newPosition = oldPosition + mCurrVelocity * (F32(TickMs) / 1000.0f);
+ //Sidewinder Stuff
+ //All else is ignored unless the setting is on
+ if(mDataBlock->isSidewinder){
+ if(mCurrTick > mDataBlock->sideDelay){
+
+ F32 Randm; //Set a temporary random variable
+
+ Randm = (rand() * mDataBlock->crazyness/(RAND_MAX +1)); //This makes the crazyness setting in the datablock
+ //the controller for how random the projectiles are
+
+ //Effect the projectiles Y velocity
+ mCurrVelocity.y += cos(mCurrVelocity.y * tan(oldPosition.x) * Randm) * mDataBlock->multiplier;
+ //Effect the X velocity
+ mCurrVelocity.x += cos(mCurrVelocity.x * sin(oldPosition.z) * Randm) * mDataBlock->multiplier;
+ //Effect the Z velocity
+ mCurrVelocity.z += cos(mCurrVelocity.z * sin(oldPosition.y) * Randm) * mDataBlock->multiplier;
+
+ }
+ }
...
}-TGE 1.5 This was found by Scooby
I appreciate your help with this.
void Projectile::processTick(const Move* move)
{
Parent::processTick(move);
...
oldPosition = mCurrPosition;
if(mDataBlock->isBallistic)
mCurrVelocity.z -= 9.81 * mDataBlock->gravityMod * (F32(TickMs) / 1000.0f);
newPosition = oldPosition + mCurrVelocity * (F32(TickMs) / 1000.0f);
+ //Sidewinder Stuff
+ //All else is ignored unless the setting is on
+ if(mDataBlock->isSidewinder){
+ if(mCurrTick > mDataBlock->sideDelay){
+
+ MRandom mRandomNumber;
+ F32 Randm = mRandomNumber.randF() * mDataBlock->crazyness; //This makes the crazyness setting in the datablock
+ //the controller for how random the projectiles are
+
+ //Effect the projectiles Y velocity
+ mCurrVelocity.y += cos(mCurrVelocity.y * tan(oldPosition.x) * Randm) * mDataBlock->multiplier;
+ //Effect the X velocity
+ mCurrVelocity.x += cos(mCurrVelocity.x * sin(oldPosition.z) * Randm) * mDataBlock->multiplier;
+ //Effect the Z velocity
+ mCurrVelocity.z += cos(mCurrVelocity.z * sin(oldPosition.y) * Randm) * mDataBlock->multiplier;
+
+ }
+ }
...
}Here is what you get from the final product.
About the author
#2
02/20/2009 (10:21 am)
Cool stuff. Thanks for sharing.
#3
02/20/2009 (10:50 am)
Thank you!!
#4
02/20/2009 (11:07 am)
Nice work.
#5
02/20/2009 (12:03 pm)
Video seems to be unavailable, sounds really neat though.
#6
I've tried embedding the video multiple times but its not worked for me yet
If some one can give me suggestions or help with the embedded video stuff I'd greatly appreciate it
02/20/2009 (12:49 pm)
Yeah you'll have to use the URL directly to the Video,I've tried embedding the video multiple times but its not worked for me yet
If some one can give me suggestions or help with the embedded video stuff I'd greatly appreciate it
#7
02/20/2009 (1:32 pm)
Great work. This is just what I need for a project I am working on.
#8
+ F32 Randm; //Set a temporary random variable
+
+ Randm = (rand() * mDataBlock->crazyness/(RAND_MAX +1)); //This makes the crazyness setting in the datablock
+ //the controller for how random the projectiles are
+
line to
MRandom mRandomNumber;
F32 Randm = mRandomNumber.randF() * mDataBlock->crazyness; //This makes the crazyness setting in the datablock
to get it to compile
02/20/2009 (3:08 pm)
hmm I had to change the+ F32 Randm; //Set a temporary random variable
+
+ Randm = (rand() * mDataBlock->crazyness/(RAND_MAX +1)); //This makes the crazyness setting in the datablock
+ //the controller for how random the projectiles are
+
line to
MRandom mRandomNumber;
F32 Randm = mRandomNumber.randF() * mDataBlock->crazyness; //This makes the crazyness setting in the datablock
to get it to compile
#9
Excellent script, really cool effect, this will definitely be useful in my project. Thanks a bunch.
02/21/2009 (11:56 pm)
I had the same issue as Scooby and his fix worked. I am running TGE 1.5.2, Not sure if that is the issue or not.Excellent script, really cool effect, this will definitely be useful in my project. Thanks a bunch.
#10
I'm currently running TGEA 1.8.1 and I guess the way the engine handles calls like the Random settings are a little different.
Earlier this week I created a weapon that mounted to a car to use this, it was awesome although I couldn't aim it all that well lol
02/23/2009 (10:39 pm)
I'm glad to see that we got this worked out, I'll change the resource to add in your fix.I'm currently running TGEA 1.8.1 and I guess the way the engine handles calls like the Random settings are a little different.
Earlier this week I created a weapon that mounted to a car to use this, it was awesome although I couldn't aim it all that well lol
#11
02/24/2009 (2:47 pm)
your welcome sir glad to help :) very nice resource it has helped me tremendously. Also int tge 1.5.2 has anyone noticed that sometimes the particles don't follow the projectile enough and the explosion will be way off
#12
Edit: Volley Successful :)
02/24/2009 (6:30 pm)
Awesome compiled and checked.. mixed this with the guided missles :) wonderfully mean :) and fun.. now to fire this as a volleyEdit: Volley Successful :)
#13
However, there is a bug I have been noticing quite often now (I'm using TGE 1.4.2, projectile muzzle velocity is 115, craziness 500, sideDelay 50, multiplier 1.1). The rocket will go on its way, but will collide and explode in the wrong place:
Here you can see where the rocket trail abruptly ends and where the engine thinks that the rocket hit, on the mountain. This only happens sometimes, especially when the rocket flies close to other level geometry. Any known fixes?
05/05/2009 (7:50 pm)
Awesome resource, thank you Brian! Got my RPGs working the way I want them :DHowever, there is a bug I have been noticing quite often now (I'm using TGE 1.4.2, projectile muzzle velocity is 115, craziness 500, sideDelay 50, multiplier 1.1). The rocket will go on its way, but will collide and explode in the wrong place:
Here you can see where the rocket trail abruptly ends and where the engine thinks that the rocket hit, on the mountain. This only happens sometimes, especially when the rocket flies close to other level geometry. Any known fixes?
#14
08/25/2009 (11:13 pm)
Brian I am very near releasing version 2 of my Enhanced projectiles resource and I wanted to see if you would mind if I add your resource as part of the whole package. Of course you will be given full credit for your work. 
Torque Owner Kirchgessner
Prosimian Productions
You don't have to add that I did so it was a little more readable and so I could add in the comments explaining the code.
Tell me what you think