Fix "bouncing projectile" problem
by Matt "Mr. Pig" Razza · 02/01/2006 (4:59 pm) · 20 comments
We will be editing a very small amount of code in projectile.cc.
Let's open it up.
Around line 780 is
The first few lines of this function are as follows:
Let's change that to:
Now below the closing } of the processTick function add:
After the getSpeed function add this function:
Lastly, we need to add the lines in the header file:
After
Add
And after that add:
Save and compile.
----------------------------
I may have left something out as I had to edit this multible times (noticing my mistakes). Let me know if you find something. Feel free to add a "Special Thanks to Matt Razza" in your game's about page. ;)
Let's open it up.
Around line 780 is
void Projectile::processTick(const Move* move).
The first few lines of this function are as follows:
void Projectile::processTick(const Move* move)
{
Parent::processTick(move);
mCurrTick++;
if(mSourceObject && mCurrTick > SourceIdTimeoutTicks)
{
mSourceObject = 0;
mSourceObjectId = 0;
}Let's change that to:
void Projectile::processTick(const Move* move)
{
mCurrTick++;
// If the speed is too low
if (0.5 >= getSpeed() && (mCurrTick < mDataBlock->armingDelay))
{
return;
}
Parent::processTick(move);
if(mSourceObject && mCurrTick > SourceIdTimeoutTicks)
{
mSourceObject = 0;
mSourceObjectId = 0;
}Feel free to change 0.5 to anything you like, or have it set via script in the datablock.Now below the closing } of the processTick function add:
F32 Projectile::getSpeed()
{
return (abs(mCurrVelocity.x) + abs(mCurrVelocity.y) + abs(mCurrVelocity.z));
}After the getSpeed function add this function:
F32 Projectile::abs(F32 iNum) //Return the abs of a givin F32 value
{
F32 ret;
if (iNum >= 0) //If pos
{
ret = iNum; //Return number we started with
}
else //If need switch
{
ret = -1 * iNum; //Convert the num and return it
}
return ret;
}Lastly, we need to add the lines in the header file:
After
public: F32 getUpdatePriority(CameraScopeQuery *focusObject, U32 updateMask, S32 updateSkips);
Add
F32 getSpeed(); //Returns proj speed
And after that add:
F32 abs(F32 fNum); //Return the abs
Save and compile.
----------------------------
I may have left something out as I had to edit this multible times (noticing my mistakes). Let me know if you find something. Feel free to add a "Special Thanks to Matt Razza" in your game's about page. ;)
#2
Let me check.
[EDIT]
They work fine for me. You must have done something wrong.
02/02/2006 (12:03 pm)
I have not had this happen to me.Let me check.
[EDIT]
They work fine for me. You must have done something wrong.
#3
Edit: Works now, projectiles show up. But the grenades still shake some.
02/02/2006 (1:48 pm)
Must have, or maybe it doesn't work in TSE. Though the projectile code snippets are the same, it appears.Edit: Works now, projectiles show up. But the grenades still shake some.
#4
I'm working on a nade setting so that the nades can explode in the air and don't need to hit the ground. Before I was scheduling them in script (the explosions), but they do not appear in a multiplayer game. The engine crashes with my current code, but I'll figure it out.
Anyway, good luck with everything.
02/02/2006 (2:13 pm)
Yeah, this is true. They give a small "buzz", it's still better then when it started.I'm working on a nade setting so that the nades can explode in the air and don't need to hit the ground. Before I was scheduling them in script (the explosions), but they do not appear in a multiplayer game. The engine crashes with my current code, but I'll figure it out.
Anyway, good luck with everything.
#5
02/02/2006 (2:41 pm)
Schedules don't show up with multiple players? Darn. That's how I had my grenades set up to explode. :(
#6
02/02/2006 (3:34 pm)
yeah thats how my grenade resource is set up.
#7
I'll let you know.
02/02/2006 (5:39 pm)
You can't have an explosion (from a scheudle) be triggered on all clients. I'm working on a fix right now (the engine crashes at this point though).I'll let you know.
#8
Anyone who applyed this before the date of this post.
02/04/2006 (11:58 am)
NOTE! IF YOUR OBJECT/NADE IS STILL BOUNCING AFTER YOU APPLED THIS FIX PLEASE READ THE EDITED VERSION.Anyone who applyed this before the date of this post.
#9
02/04/2006 (3:37 pm)
Now it definitely fixes it. But a projectile particle trail stops when the grenade stops too. That's my only nag. :P (I have a light smoke trail on my grenades, and it makes a nice way to see where you threw your grenade)
#10
02/04/2006 (7:15 pm)
Oh, I didn't consider that. Let me look into it.
#11
02/05/2006 (10:03 am)
I finished my nade system. It works great! I'd send you the code (or post it) but I would like to perfect it first.
#12
02/05/2006 (2:15 pm)
AKA, you got the explosions working? Woot!
#13
.onExplode where you apply damage.
After I perfect it, I may sell my Projectile.cc as a bundle being that in contains support for 12 differenct projectiles. (Not just nades and bullets).
I had to have spent 6days stright on those files.. so...
We'll see.
02/05/2006 (2:50 pm)
;) You set the var isNade in the projectile datablock then set the time until it explodes (2 seconds is 2000 milliseconds, so in the datablock you do 2000/32). When 2 seconds pass it goes boom and runs After I perfect it, I may sell my Projectile.cc as a bundle being that in contains support for 12 differenct projectiles. (Not just nades and bullets).
I had to have spent 6days stright on those files.. so...
We'll see.
#14
02/05/2006 (3:27 pm)
Hmm. What other types of projectiles are there?
#15
02/05/2006 (5:47 pm)
Oh, you'll see, you'll see. ;)
#16
02/21/2006 (10:24 pm)
Would love to see the outcome
#17
02/22/2006 (12:05 pm)
When I finish revamping the lighting engine. I think I'll post some screens.
#18
02/22/2006 (5:42 pm)
Woot!
#19
04/02/2006 (5:38 pm)
Any updates?
#20
04/02/2006 (5:52 pm)
Oh sorry - been really really busy. I don't know when I'll get around to doing it... sorry. 
Torque Owner Chris Byars
Ion Productions