Jetting Up and Down
by Mark Strahan · in Torque Game Engine · 01/14/2009 (9:06 am) · 11 replies
Using the basic Torque Engine I can Jet up, but I want to set a zero gravity environment and be able to Jet down. Does anyone have any ideas for jetting down or hovering up and down?
#3
I want the players gravity to become -40.0 when you press "q" and 40.0 when you press the "e" key.
This allows the player to move up and down in zero gravity.
01/28/2009 (9:54 am)
I am attempting to chgne the player gravity by pressing the "q" and "e" key.I want the players gravity to become -40.0 when you press "q" and 40.0 when you press the "e" key.
This allows the player to move up and down in zero gravity.
#4
function markdown( %val )
{
F32 Player::mGravity = -20;
}
moveMap.bind( keyboard, e, markdown );
function markup( %val )
{
F32 Player::mGravity = 20;
}
moveMap.bind( keyboard, e, markup );
02/16/2009 (7:56 pm)
I've reloaded v1.7.1 of TGE and modified default.bind.cs, but did not see any changes. Any suggestions to make this work? I made the following changes to default.bind.cs:function markdown( %val )
{
F32 Player::mGravity = -20;
}
moveMap.bind( keyboard, e, markdown );
function markup( %val )
{
F32 Player::mGravity = 20;
}
moveMap.bind( keyboard, e, markup );
#5
First, F32 Player::mGravity is a static F32.
Once it is set it is meant to stay the same value throughout the class.
If you want it to change simply remove the static from it's declaration.
From this
Now move the setting of mGravity to constructor.
Next
I don't know where in the code you are placing this
But it simply won't work.
Too many things wrong to point them all out.
I will try and write out a more detailed explanation when I get off work.
02/17/2009 (6:40 am)
Where to begin.First, F32 Player::mGravity is a static F32.
Once it is set it is meant to stay the same value throughout the class.
If you want it to change simply remove the static from it's declaration.
From this
static F32 mGravity; ///< GravityTo this
F32 mGravity; ///< Gravity
Now move the setting of mGravity to constructor.
Player::Player()
{
mGravity = 0.0f;
...Next
I don't know where in the code you are placing this
while(stream->writeFlag(GravUpNew))
{
F32 Player::mGravity = 40.0;
}
while(stream->writeFlag(GravDownNew))
{
F32 Player::mGravity = -40.0;
}
}But it simply won't work.
Too many things wrong to point them all out.
I will try and write out a more detailed explanation when I get off work.
#6
02/17/2009 (1:17 pm)
I hope you guys know you're posting this in the public forum... you're not suppose to reveal source code here, right?
#7
Have you ever seen whats in the very public resources.
What I think they frown on is posting links to zips with multiple classes , most of which my be only slightly modified code, in the public side of the forums.
02/17/2009 (4:28 pm)
I don't think GG has ever worried about a hand full of lines of code posted on the public side.Have you ever seen whats in the very public resources.
What I think they frown on is posting links to zips with multiple classes , most of which my be only slightly modified code, in the public side of the forums.
#8
I just need to know if its TGE or TGEA. You made reference to 1.7.1 of TGE.
If it's TGEA I have a relatively simple solution for you.
02/17/2009 (4:33 pm)
@Mark - What version are you trying to modify.I just need to know if its TGE or TGEA. You made reference to 1.7.1 of TGE.
If it's TGEA I have a relatively simple solution for you.
#9
02/17/2009 (4:39 pm)
It is TGEA.
#10
Open player.cpp and in void Player::updateMove(const Move* move) find
And change it to
The bold is what was added.
Save then recompile.
Then open your default.bind.cs script file, it should be in the game\scriptsAndAssets\client\scripts folder and add
Save and run your game and if you have removed gravity via setting F32 SpacePlayer::mGravity to 0 it should do exactly what you want.
Pressing the right mouse button will jet you up and pressing the middle mouse button will jet you down.
Keep in mind there are several ways to do what you want but this seems to be the simplest.
02/17/2009 (6:31 pm)
Ok this will be easy.Open player.cpp and in void Player::updateMove(const Move* move) find
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;
}And change it to
if ([b]([/b]move->trigger[1][b] || move->trigger[3])[/b] && !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)
[b] if(move->trigger[3])
acc.z += -mJumpSurfaceNormal.z * impulse * zSpeedScale;
else[/b]
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;
}The bold is what was added.
Save then recompile.
Then open your default.bind.cs script file, it should be in the game\scriptsAndAssets\client\scripts folder and add
function jetDownTrigger(%val)
{
$mvTriggerCount3++;
}
moveMap.bind( mouse, button2, jetDownTrigger );Save and run your game and if you have removed gravity via setting F32 SpacePlayer::mGravity to 0 it should do exactly what you want.
Pressing the right mouse button will jet you up and pressing the middle mouse button will jet you down.
Keep in mind there are several ways to do what you want but this seems to be the simplest.
Torque Owner S2P
Something2Play