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.
#2
03/25/2005 (3:48 pm)
I'm sorry, but I've been searching for hours, the closest I've gotten is a swimming resource, but it didn't do what I wanted exactly. Please give me a link if you know of one
#3
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=7079
03/25/2005 (4:04 pm)
Did you see this one yet?www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=7079
#4
Thats the part I don't know how to fix
03/25/2005 (4:23 pm)
"Now all i need to do is modify the simple flight to not move up or down when you look those directions , but to only move in whatever direction you are looking when you press forward."Thats the part I don't know how to fix
#5
What i am doing is just mounting him on flying vechicles, modifying the code so he can still animate and trigger weapons and also modifying some vechicle code so it can act like a flying carpet. press left it goes left... etc
03/25/2005 (4:36 pm)
I was going to use that code as i needed a flying player. But he rides a variety of objects, flying carpets, dragons other creatures. So adding code to make my player fly would not work for my case.What i am doing is just mounting him on flying vechicles, modifying the code so he can still animate and trigger weapons and also modifying some vechicle code so it can act like a flying carpet. press left it goes left... etc
#6
I'll continue to try, I'm pretty close, but its very very difficult to get it so that it doesn't have a 2d vector... I'm not even sure where I need to look in order to make it 3d...
03/25/2005 (6:28 pm)
My players will be able to fly without vehicles, but also there will be vehicles and I'm trying to make it so that the player flight isn't dependant on using vehicles...I'll continue to try, I'm pretty close, but its very very difficult to get it so that it doesn't have a 2d vector... I'm not even sure where I need to look in order to make it 3d...
#8
Turns out, both of these isn't what I want.
The first one is the thing that tells the engine the player wants to move forward, right? Well, zRot only tells the X and Y planes, but not the Z. (if you think about it, since the Z axis points up and down, then it wouldn't be in its range to see up and down, just left and right) The second one just says that when you press move up or move down, then it moves you up, or down. (I binded them to my page up and down keys, and it works that way)
The solution is to instead get the head.x rotation, and use THAT for moving. The problem, however, is the X axis only returns up and down movement, and not left and right... so when you move, you do get up and down movement, but in the actual game, you only move on an axis.
The solution for THAT is what I'm figuring out now. I'll post as soon as I figure it out.
Hopefully this topic is filling in the holes of player flying.
03/26/2005 (5:12 am)
Thank you for all your help, I think I finally solved it... It was a complete oversight on my part, and it seems so simple now that I look at it.zRot.getColumn(0,&moveVec);
moveVec *= move->x;
...
// Flying
zRot.getColumn(2,&tv);
moveVec += tv * move->z;
// End FlyingTurns out, both of these isn't what I want.
The first one is the thing that tells the engine the player wants to move forward, right? Well, zRot only tells the X and Y planes, but not the Z. (if you think about it, since the Z axis points up and down, then it wouldn't be in its range to see up and down, just left and right) The second one just says that when you press move up or move down, then it moves you up, or down. (I binded them to my page up and down keys, and it works that way)
The solution is to instead get the head.x rotation, and use THAT for moving. The problem, however, is the X axis only returns up and down movement, and not left and right... so when you move, you do get up and down movement, but in the actual game, you only move on an axis.
The solution for THAT is what I'm figuring out now. I'll post as soon as I figure it out.
Hopefully this topic is filling in the holes of player flying.
#9
There you go!
Goodluck to everyone.
03/26/2005 (5:26 am)
Finally, after hours of trying to figure it out. I hope this helps anyone looking for flying players!!delta.head = mHead;
delta.headVec -= mHead;
}
[b] MatrixF zRot,xRot,superRot;[/b]
zRot.set(EulerF(0, 0, mRot.z));
[b] xRot.set(EulerF(mHead.x, 0, 0));
superRot.mul(zRot, xRot);[/b]
// Desired move direction & speed
VectorF moveVec;
F32 moveSpeed;
if (mState == MoveState && mDamageState == Enabled)
{
zRot.getColumn(0,&moveVec);
moveVec *= move->x;
VectorF tv;
[b] superRot.getColumn(1,&tv);
moveVec += tv * move->y;
// Flying -- Zshazz
zRot.getColumn(2,&tv);
moveVec += tv * move->z;
// End Flying[/b]There you go!
Goodluck to everyone.
#10
03/26/2005 (5:49 am)
Im glad you got it to work, ill refer people to this thread if i see this mentioned again.
#11
03/26/2005 (7:03 am)
Good job. Thanks for posting your solution.
#12
03/26/2005 (8:57 pm)
You're welcome, I just hope that I help at least one other person with their coding ^_^
#13
04/07/2005 (1:36 pm)
Chris - I've been working on the exact same thing when I finally came upon this forum by accident! I implemented your new flying code, but my avatar still runs around along the terrain. Am I missing something that is not mentioned here?
#14
04/07/2005 (1:44 pm)
I'm sorry, there is a little bit that I didn't quite add here... Sometime soon I'm gonna make a resource for it, but it'll take far too long for it to appear. I'll work for about 30 minutes to make a little mini resource and post it right here to help you.
#15
Now, open Player.cc
Player::Player()
Player::updateMove()
Edit: Removed variRunforce, should work now!
04/07/2005 (2:20 pm)
First, Open Player.h and add this:class Player: public ShapeBase
{
...
S32 mMountPending; ///< mMountPending suppresses tickDelay countdown so players will sit until
///< their mount, or another animation, comes through (or 13 seconds elapses).
[B] // Flying -- Zshazz
bool mIsFlying;
// End Flying[/B]
/// Main player state
enum ActionState {
NullState,
...Now, open Player.cc
Player::Player()
Player::Player()
{
...
dMemset( mSplashEmitter, 0, sizeof( mSplashEmitter ) );
[B] // Flying -- Zshazz
mIsFlying = true;
// End Flying[/B]
mImpactSound = 0;
...
}Player::updateMove()
void Player::updateMove(const Move* move)
{
delta.move = *move;
...
delta.headVec -= mHead;
}
[B] // Flying -- Zshazz
MatrixF zRot,xRot,superRot;
zRot.set(EulerF(0, 0, mRot.z));
xRot.set(EulerF(mHead.x, 0, 0));
if (mIsFlying)
superRot.mul(zRot, xRot);
else
superRot = zRot;
// End Flying[/B]
// Desired move direction & speed
VectorF moveVec;
F32 moveSpeed;
if (mState == MoveState && mDamageState == Enabled)
{
zRot.getColumn(0,&moveVec);
moveVec *= move->x;
VectorF tv;
[B] superRot.getColumn(1,&tv); // One Line for flight[/B]
moveVec += tv * move->y;
if (move->y > 0)
{
...
// Acceleration due to gravity
[B] // Flying -- Zshazz
VectorF acc(0,0,mGravity * mGravityMod * TickSec);
if (mIsFlying)
acc.set(0,0,0);
// End Flying[/B]
// Determine ground contact normal. Only look for contacts if
// we can move.
...
acc += runAcc;
// If we are running on the ground, then we're not jumping
if (mDataBlock->isJumpAction(mActionAnimation.action))
mActionAnimation.action = PlayerData::NullAnimation;
}
else
mContactTimer++;
[B] // Flying -- Zshazz
if (mIsFlying)
{
F32 impulse = mDatablock->runForce / mMass; // The impulse that is going to be applied
// 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 Flying [/B]
if (move->trigger[2] && canJump())
{
...
}Edit: Removed variRunforce, should work now!
#16
Player::unpackUpdate()
You can implement ways in order to turn on and off flying by modifying the mIsFlying variable... if its false, then the player will stop flying, if its true, he stays flying. Later when I make the bigger resource, I'll have more complete information (like, how to make it so the player tilts back and forward) but for now, this will get your player flying.
I hope this helps you out!!! I worked hard on figuring out how to make it works, and I just hope it'll make your life easier ^_^
04/07/2005 (2:21 pm)
Player::packUpdate()U32 Player::packUpdate(NetConnection *con, U32 mask, BitStream *stream)
{
U32 retMask = Parent::packUpdate(con, mask, stream);
if (stream->writeFlag((mask & ImpactMask) && !(mask & InitialUpdateMask)))
stream->writeInt(mImpactSound, PlayerData::ImpactBits);
[B] // Flying -- Zshazz
stream->writeFlag(mIsFlying);
// End of Flying[/B]
if (stream->writeFlag(mask & ActionMask &&
mActionAnimation.action != PlayerData::NullAnimation &&
...
}Player::unpackUpdate()
void Player::unpackUpdate(NetConnection *con, BitStream *stream)
{
Parent::unpackUpdate(con,stream);
if (stream->readFlag())
mImpactSound = stream->readInt(PlayerData::ImpactBits);
[B] // Flying -- Zshazz
mIsFlying = stream->readFlag();
// End Flying[/B]
// Server specified action animation
...
}You can implement ways in order to turn on and off flying by modifying the mIsFlying variable... if its false, then the player will stop flying, if its true, he stays flying. Later when I make the bigger resource, I'll have more complete information (like, how to make it so the player tilts back and forward) but for now, this will get your player flying.
I hope this helps you out!!! I worked hard on figuring out how to make it works, and I just hope it'll make your life easier ^_^
#17
04/08/2005 (6:56 am)
Chris - thanks for replying to my post! Indeed, this will be an enormous help to me, but I can't seem to get it to work. My avatar won't move - he's stuck! Also, could you tell me what variRunForce is? I've tried various arbitrary constants, but nothing seems to work so I'm guessing there something more to it that I'm missing...
#18
Sorry about that, I implemented another bit of other coding into it and forgot that part... tell me if theres any more weird stuff.
04/08/2005 (4:56 pm)
Oooooops! Sorry, replace variRunForce with mDataBlock->runForceSorry about that, I implemented another bit of other coding into it and forgot that part... tell me if theres any more weird stuff.
#19
04/12/2005 (7:11 am)
Hooray! It works beautifully - thank you so much for your help Chris! This will be a great resource!
#20
I still don't understand what packUpdate/UnPackUpdate do. I'm guessing this is a way you can turn on/off flying in game, but I'm still pretty new to this, so I'm not sure how they hook in.
Again thanks a mil.
SpaceCowboy
04/20/2005 (4:53 pm)
Thank you very much! I was able to get my player flying in about 10 minutes following your examples! I still don't understand what packUpdate/UnPackUpdate do. I'm guessing this is a way you can turn on/off flying in game, but I'm still pretty new to this, so I'm not sure how they hook in.
Again thanks a mil.
SpaceCowboy
Torque Owner Steve Lamperti
Imagine That!
This is not trivial. There are several other threads, and a couple of resources devoted to this topic. Try a search.