T3D Jetpack Function
by Kiyaku · in Torque Game Engine Advanced · 08/20/2008 (12:23 am) · 4 replies
Hi,
in the T3D demo (the one with the boombot and polysoup models) you can use a jetpack when you hold the right mouse button.
I wanted to create something simliar and used applyImpulse for it.
But i wanted to check how it is done in the T3D demo, though i can't really find the code for it.
I looked up the default.bind.cs. The right mouse button opens the function "alttrigger" which just increase the var "$mvTriggerCount1" by 1. That's it. i searched for the same variable in every script file but couldn't find it.
Is it coded in C++ or do i miss something?
Thanks in advance!
in the T3D demo (the one with the boombot and polysoup models) you can use a jetpack when you hold the right mouse button.
I wanted to create something simliar and used applyImpulse for it.
But i wanted to check how it is done in the T3D demo, though i can't really find the code for it.
I looked up the default.bind.cs. The right mouse button opens the function "alttrigger" which just increase the var "$mvTriggerCount1" by 1. That's it. i searched for the same variable in every script file but couldn't find it.
Is it coded in C++ or do i miss something?
Thanks in advance!
#2
for(U32 i = 0; i < MaxTriggerKeys; i++)
{
char varName[256];
dSprintf(varName, sizeof(varName), "mvTriggerCount%d", i);
Con::addVariable(varName, TypeS32, &mTriggerCount[i]);
}
so now i just have to find out what exactly this trigger no. 1 will execute in the code to trigger the "jetpack" function.
Thanks so far!
08/20/2008 (2:18 am)
Thanks, i could find the code where the variables gets created:for(U32 i = 0; i < MaxTriggerKeys; i++)
{
char varName[256];
dSprintf(varName, sizeof(varName), "mvTriggerCount%d", i);
Con::addVariable(varName, TypeS32, &mTriggerCount[i]);
}
so now i just have to find out what exactly this trigger no. 1 will execute in the code to trigger the "jetpack" function.
Thanks so far!
#3
08/20/2008 (2:45 am)
The jetting code itself is in player.cpp. I'm not entirely sure if it links into the trigger code there too, though.
#4
08/20/2008 (2:46 am)
Thanks, i found it. The trigger variable isn't the same as mTriggerCount.if (move->trigger[1] && !isMounted() && canJetJump())
{
mJetting = true;
// Scale the jump impulse base on maxJumpSpeed
F32 zSpeedScale = mVelocity.z;
if (zSpeedScale <= mDataBlock->jetMaxJumpSpeed)
{
zSpeedScale = (zSpeedScale <= mDataBlock->jetMinJumpSpeed)? 1:
1 - (zSpeedScale - mDataBlock->jetMinJumpSpeed) / (mDataBlock->jetMaxJumpSpeed - mDataBlock->jetMinJumpSpeed);
// Desired jump direction
VectorF pv = moveVec;
F32 len = pv.len();
if (len > 0.0f)
pv *= 1 / len;
// If we are facing into the surface jump up, otherwise
// jump away from surface.
F32 dot = mDot(pv,mJumpSurfaceNormal);
F32 impulse = mDataBlock->jetJumpForce / mMass;
if (dot <= 0)
acc.z += mJumpSurfaceNormal.z * impulse * zSpeedScale;
else
{
acc.x += pv.x * impulse * dot;
acc.y += pv.y * impulse * dot;
acc.z += mJumpSurfaceNormal.z * impulse * zSpeedScale;
}
mEnergy -= mDataBlock->jetJumpEnergyDrain;
}
}
Torque 3D Owner Ashley Leach
mTriggerCount[i]
search in the engine for mvTriggerCount
so access that one as mTriggerCount[1]
-Ash