Twirling Projectile for Grenade
by Mquaker · 09/04/2011 (10:34 pm) · 7 comments
open projectile.h
add code in 'class ProjectileData : public GameBaseData'
after
open projectile.cpp
add code 'ProjectileData::ProjectileData()'
after
add code in 'void ProjectileData::initPersistFields()'
after
add code in 'void ProjectileData::packData()'
after
add code in 'void ProjectileData::unpackData()'
find and replace code in 'void Projectile::interpolateTick()'
replace to
and add code same function
after
ok, recompile and add one value to your grenade ProjectileData.
if true, your projectile twirling.
add code in 'class ProjectileData : public GameBaseData'
bool misGrenade;
after
/// Should it arc? bool isBallistic;
open projectile.cpp
add code 'ProjectileData::ProjectileData()'
misGrenade = false;
after
faceViewer = false; scale.set( 1.0f, 1.0f, 1.0f ); isBallistic = false;
add code in 'void ProjectileData::initPersistFields()'
addField("isGrenade", TypeBool, Offset(misGrenade, ProjectileData), "@brief if true, projectile twirling");after
addField("isBallistic", TypeBool, Offset(isBallistic, ProjectileData),
"@brief Detetmines if the projectile should be affected by gravity and whether or not "
"it bounces before exploding.nn");add code in 'void ProjectileData::packData()'
stream->writeFlag(misGrenade);
after
if(stream->writeFlag(isBallistic))
{
stream->write(gravityMod);
stream->write(bounceElasticity);
stream->write(bounceFriction);
}add code in 'void ProjectileData::unpackData()'
misGrenade = stream->readFlag();
find and replace code in 'void Projectile::interpolateTick()'
if(dir.isZero())
dir.set(0,0,1);
else
dir.normalize();replace to
if (mDataBlock->misGrenade) {
if (mCurrVelocity.len() < 3.0f)
dir.set(0.0f,1.0f,0.0f);
else
dir.normalize();
}
else {
if (dir.isZero())
dir.set(0.0f,0.0f,1.0f);
else
dir.normalize();
}and add code same function
if (mDataBlock->misGrenade) {
if (mCurrVelocity.len() > 3.0f) {
MatrixF xZRot(true);
VectorF ZRotVec;
MathUtils::getVectorFromAngles(ZRotVec, 0.0f, F32(mCurrTick));
xZRot = MathUtils::createOrientFromDir(Point3F(ZRotVec.x, ZRotVec.y, ZRotVec.z));
xform = xform * xZRot;
}
}after
MatrixF xform(true); xform = MathUtils::createOrientFromDir(dir);
ok, recompile and add one value to your grenade ProjectileData.
isGrenade = true;
if true, your projectile twirling.
About the author
visit : http://www.quakedev.net
#2
i added one value for control rotate speed.
open projectile.h and add this code
after
open projectile.cpp and add this code
after
find 'void ProjectileData::initPersistFields()' function and add this code
after
find 'stream->writeFlag(misGrenade);' in 'void ProjectileData::packData()' function and replace code
find 'misGrenade = stream->readFlag();' in 'void ProjectileData::unpackData()' function and below add this code
find 'MathUtils::getVectorFromAngles(ZRotVec, 0.0f, F32(mCurrTick));' code block and replace to this code
ok, recompile your project.
find 'isGrenade = true;' in your 'projectiledata' and add below this code.
09/05/2011 (5:48 am)
@David : thanks.i added one value for control rotate speed.
open projectile.h and add this code
F32 mRotSpeed;
after
bool misGrenade;
open projectile.cpp and add this code
mRotSpeed = 0.5f;
after
misGrenade = false;
find 'void ProjectileData::initPersistFields()' function and add this code
addField("RotationSpeed", TypeF32, Offset(mRotSpeed, ProjectileData),
"@brief if isGrenade is true, this value active");after
addField("isBallistic", TypeBool, Offset(isBallistic, ProjectileData),
"@brief Detetmines if the projectile should be affected by gravity and whether or not "
"it bounces before exploding.nn");find 'stream->writeFlag(misGrenade);' in 'void ProjectileData::packData()' function and replace code
if(stream->writeFlag(misGrenade)) stream->write(mRotSpeed);
find 'misGrenade = stream->readFlag();' in 'void ProjectileData::unpackData()' function and below add this code
if (misGrenade) stream->read(&mRotSpeed);
find 'MathUtils::getVectorFromAngles(ZRotVec, 0.0f, F32(mCurrTick));' code block and replace to this code
F32 pitch = F32(mCurrTick) * mDataBlock->mRotSpeed; MathUtils::getVectorFromAngles(ZRotVec, 0.0f, pitch);
ok, recompile your project.
find 'isGrenade = true;' in your 'projectiledata' and add below this code.
RotationSpeed = 0.5;
#3
09/05/2011 (7:00 am)
How about a video of the code in action?
#5
09/05/2011 (9:35 am)
Nice graphics ;)
#6
09/05/2011 (2:42 pm)
@Steve Lol
#7
09/05/2011 (3:34 pm)
Interesting. I wonder if I could use this for a throwing axe. 
Torque Owner David Robert Pemberton
www.deadlyassets.com
D R Pemberton (Rob)
www.dedlyassets.com