Flying
by Chris Cain · in Torque Game Engine · 03/25/2005 (3:32 pm) · 32 replies
I've been trying all day to make a player fly. I want a player to be able to use his wsad keys in order to move in 3d (instead of in 2d, on the ground). When the client presses W then the player will move forward instead of just along the X axis.
Could anyone help me out here? I've made it so that the player can control the Z axis by pressing the moveup key
In Player::updateMove()
I was using a slightly modified Jet that I found in the resources. It works, but it doesn't do exactly what I want :(
Please help me? I've been working for over 16 hours trying to get this to work.
Could anyone help me out here? I've made it so that the player can control the Z axis by pressing the moveup key
In Player::updateMove()
...
zRot.getColumn(0,&moveVec);
moveVec *= move->x;
VectorF tv;
zRot.getColumn(1,&tv);
moveVec += tv * move->y;
// Flying
zRot.getColumn(2,&tv);
moveVec += tv * move->z;
// End Flying
...
// Flying
if(!mJetting)
{
if (mJetSound) {
alxStop(mJetSound);
mJetSound = 0;
}
}
else
{
// if (mEnergy >= mDataBlock->minJetEnergy)
// {
// mEnergy -= mDataBlock->jetEnergyDrain;
F32 impulse = mDataBlock->jetForce / mMass;
VectorF pv = moveVec;
F32 pvl = pv.len();
if (pvl)
pv *= moveSpeed / pvl;
VectorF flyAcc = pv - ( mVelocity + acc);
flyAcc.z = flyAcc.z * 1 * impulse;
//flyAcc.z = flyAcc.z * 1 * impulse;
flyAcc.x = flyAcc.x * 1 * impulse;
flyAcc.y = flyAcc.y * 1 * impulse;
F32 flySpeed = flyAcc.len();
F32 maxAcc = impulse * TickSec * 1;
if (flySpeed > maxAcc)
flyAcc *= maxAcc / flySpeed;
acc += flyAcc;
if (mDataBlock->sound[PlayerData::JetSound])
{
if (!mJetSound)
mJetSound = alxPlay(mDataBlock->sound[PlayerData::JetSound], &getTransform());
alxSourceMatrixF(mJetSound, &getTransform());
}
// }
}
// End FlyingI was using a slightly modified Jet that I found in the resources. It works, but it doesn't do exactly what I want :(
Please help me? I've been working for over 16 hours trying to get this to work.
#22
04/21/2005 (8:13 pm)
Actually, in my opinion it is trivial -- remove gravity, then if he is moving forward, get the forward vector of him and move with that. Backwards, inverse the forwards. Right, get the Right vector. Up, get the up vector, etc.
#23
04/21/2005 (8:23 pm)
It was a little more advanced to figure out than that, because I had to set it up to get the actual forward (X and Z), and not just forward of Z rotation
#24
04/21/2005 (9:03 pm)
Did you put in a way to toggle it on and off? A fly button?
#25
04/22/2005 (2:51 pm)
Not in the tutorial listed above, but I personally have done it that way.
#26
07/12/2005 (7:46 pm)
Nevermind typo's get me every dang time.
#27
07/14/2005 (7:29 am)
I just found and implimented this mod but am wondering why the player does not actually 'fly' but instead stays on a plain instead of falling? Like when he walks off a cliff he just continues to walk but you can not make him look up and follow that plane instead. Also the AIplayer does the same. This mod does not seem so much flying as you have no control over it.
#28
Simple flight from the link Chris Newman placed is supposed to work with the variables and parameters that are already provided in stock torque. This way, it uses the player's POV parameters to specify the pitch. If you need to the player to look up while walking on a plane, you'll need to add extra variables and parameters to the player in order to store the desired pitch ( hard work ). Once you do that is just a matter of changing the flight code to reflect them ( easy job ).
07/14/2005 (8:28 am)
@mark,Simple flight from the link Chris Newman placed is supposed to work with the variables and parameters that are already provided in stock torque. This way, it uses the player's POV parameters to specify the pitch. If you need to the player to look up while walking on a plane, you'll need to add extra variables and parameters to the player in order to store the desired pitch ( hard work ). Once you do that is just a matter of changing the flight code to reflect them ( easy job ).
#29
07/16/2005 (6:29 am)
Got it... http://www.garagegames.com/mg/forums/result.thread.php?qt=32256
#30
Chirs, Do i need to replace the whole previous code for the following,
"Player::Player()"
"Player::updateMove()"
"Player::packUpdate()"
"Player::unpackUpdate()"
or do i leave the existing code aswell as adding the new code in?
Thanks for the help! :)
11/09/2007 (4:57 am)
Hi,Chirs, Do i need to replace the whole previous code for the following,
"Player::Player()"
"Player::updateMove()"
"Player::packUpdate()"
"Player::unpackUpdate()"
or do i leave the existing code aswell as adding the new code in?
Thanks for the help! :)
#31
Did you ever get an answer to your question? I'm getting all kinds of errors when I replace. I also got an error saying the "mDatablock" was incorrect. When i changed it to "mDataBlock" (capitol B) it got passed that part, however I get the following
>..\..\..\..\..\engine\source\T3D\player.cpp(1957) : error C2601: 'Player::checkDismountPosition' : local function definitions are illegal
1> ..\..\..\..\..\engine\source\T3D\player.cpp(1485): this line contains a '{' which has not yet been matched
1>..\..\..\..\..\engine\source\T3D\player.cpp(2006) : error C2601: 'Player::canJump' : local function definitions are illegal
1> ..\..\..\..\..\engine\source\T3D\player.cpp(1485): this line contains a '{' which has not yet been matched
1>..\..\..\..\..\engine\source\T3D\player.cpp(2011) : error C2601: 'Player::canJetJump' : local function definitions are illegal
1> ..\..\..\..\..\engine\source\T3D\player.cpp(1485): this line contains a '{' which has not yet been matched
1>..\..\..\..\..\engine\source\T3D\player.cpp(2018) : error C2601: 'Player::updateDamageLevel' : local function definitions are illegal
1> ..\..\..\..\..\engine\source\T3D\player.cpp(1485): this line contains a '{' which has not yet been matched
1>..\..\..\..\..\engine\source\T3D\player.cpp(2026) : error C2601: 'Player::updateDamageState' : local function definitions are illegal
1> ..\..\..\..\..\engine\source\T3D\player.cpp(1485): this line contains a '{' which has not yet been matched
1>..\..\..\..\..\engine\source\T3D\player.cpp(2044) : error C2601: 'Player::updateLookAnimation' : local function definitions are illegal
I am still working the problem... i am assuming that I missed a "}" somewhere.
Thanks
P
07/26/2008 (11:04 pm)
Flame, Did you ever get an answer to your question? I'm getting all kinds of errors when I replace. I also got an error saying the "mDatablock" was incorrect. When i changed it to "mDataBlock" (capitol B) it got passed that part, however I get the following
>..\..\..\..\..\engine\source\T3D\player.cpp(1957) : error C2601: 'Player::checkDismountPosition' : local function definitions are illegal
1> ..\..\..\..\..\engine\source\T3D\player.cpp(1485): this line contains a '{' which has not yet been matched
1>..\..\..\..\..\engine\source\T3D\player.cpp(2006) : error C2601: 'Player::canJump' : local function definitions are illegal
1> ..\..\..\..\..\engine\source\T3D\player.cpp(1485): this line contains a '{' which has not yet been matched
1>..\..\..\..\..\engine\source\T3D\player.cpp(2011) : error C2601: 'Player::canJetJump' : local function definitions are illegal
1> ..\..\..\..\..\engine\source\T3D\player.cpp(1485): this line contains a '{' which has not yet been matched
1>..\..\..\..\..\engine\source\T3D\player.cpp(2018) : error C2601: 'Player::updateDamageLevel' : local function definitions are illegal
1> ..\..\..\..\..\engine\source\T3D\player.cpp(1485): this line contains a '{' which has not yet been matched
1>..\..\..\..\..\engine\source\T3D\player.cpp(2026) : error C2601: 'Player::updateDamageState' : local function definitions are illegal
1> ..\..\..\..\..\engine\source\T3D\player.cpp(1485): this line contains a '{' which has not yet been matched
1>..\..\..\..\..\engine\source\T3D\player.cpp(2044) : error C2601: 'Player::updateLookAnimation' : local function definitions are illegal
I am still working the problem... i am assuming that I missed a "}" somewhere.
Thanks
P
#32
Thanks for the great post Chris!! I am just starting with Torque and i am working towards a Decent II type of remake for fun. I don't know if this is the way I should be going, but its helping me understand how Torque works..
so the whole thing with Chris' code and the default code is --
P
07/26/2008 (11:14 pm)
Sorry, guess i should have tried it before asking... in the player.ccp I had replaced the follwing code with the code from Chris' post... however that didn't work. so I uncommented the code below and everything worked just fine... I am guessing since his post was from 05 that he was running a different version of TGEA... I am using 1.7.1.Thanks for the great post Chris!! I am just starting with Torque and i am working towards a Decent II type of remake for fun. I don't know if this is the way I should be going, but its helping me understand how Torque works..
if (!inLiquid && mDataBlock->airControl > 0.0f)
{
VectorF pv;
pv = moveVec;
F32 pvl = pv.len();
if (pvl)
pv *= moveSpeed / pvl;
VectorF runAcc = pv - acc;
runAcc.z = 0;
runAcc.x = runAcc.x * mDataBlock->airControl;
runAcc.y = runAcc.y * mDataBlock->airControl;
F32 runSpeed = runAcc.len();
F32 maxAcc = (mDataBlock->runForce / mMass) * TickSec * 0.3f;
if (runSpeed > maxAcc)
runAcc *= maxAcc / runSpeed;
acc += runAcc;
}
}
// Acceleration from Jumpingso the whole thing with Chris' code and the default code is --
if (mDataBlock->isJumpAction(mActionAnimation.action))
mActionAnimation.action = PlayerData::NullAnimation;
}
else
{
mContactTimer++;
if (!inLiquid && mDataBlock->airControl > 0.0f)
{
VectorF pv;
pv = moveVec;
F32 pvl = pv.len();
if (pvl)
pv *= moveSpeed / pvl;
VectorF runAcc = pv - acc;
runAcc.z = 0;
runAcc.x = runAcc.x * mDataBlock->airControl;
runAcc.y = runAcc.y * mDataBlock->airControl;
F32 runSpeed = runAcc.len();
F32 maxAcc = (mDataBlock->runForce / mMass) * TickSec * 0.3f;
if (runSpeed > maxAcc)
runAcc *= maxAcc / runSpeed;
acc += runAcc;
}
}
// Acceleration from Jumping
// Flying -- Zshazz
if (mIsFlying)
{
F32 impulse = mDataBlock->runForce / mMass; // The impulse that is going to be applied-- Changed mDatablock to mDataBlock from error report.
// Get the move vector
VectorF pv = moveVec;
F32 pvl = pv.len();
if (pvl)
pv *= moveSpeed / pvl;
// Initialize flyAcc
VectorF flyAcc = pv - ( mVelocity + acc);
//Apply the impulse to vector
flyAcc *= impulse;
// flyAcc.x *= impulse;
// flyAcc.y *= impulse;
// flyAcc.z *= impulse;
// Get ready to limit the acceleration
F32 flySpeed = flyAcc.len();
F32 maxAcc = impulse * TickSec;
// Limit the acceleration
if (flySpeed > maxAcc)
flyAcc *= maxAcc / flySpeed;
// Apply the flying acceleration to the total acceleration.
acc += flyAcc;
}
// End FlyingThanks againP
Torque 3D Owner Chris Cain