Making a Player Fly
by Mark Pumphrey · in Torque Game Engine · 07/15/2005 (3:31 am) · 125 replies
Firstly I would like to state that "Yeah, I have seen the posts about flying but....". They don't work and/or full of bugs. I would like to also state a general request that if you make a post regarding code to edit the original post instead continually trying to 'add' corrections later on making it harder than hell to read. Also, EVERYONE has a copy and paste function of some kind, use it. Saying that "here is some code than will change your life, insert it anywhere" means nothing and helps even less. Ok, enough of that. Has anyone actually made a player fly just like in Tribes?
#2
First find the line
and change it to
Next scroll down just a little and find
and change it to
Then scroll down a bit more and find
and change it to
07/15/2005 (5:49 pm)
In engine\game\player.cc goto the function Player::updateMov()First find the line
// Acceleration due to gravity VectorF acc(0,0,mGravity * mGravityMod * TickSec);
and change it to
// Acceleration due to gravity VectorF acc(0,0,0);
Next scroll down just a little and find
// Acceleration on run surface
if (runSurface) {
mContactTimer = 0;and change it to
// Acceleration on run surface
if (true) {
mContactTimer = 30;Then scroll down a bit more and find
if (pvl) {
VectorF nn;
mCross(pv,VectorF(0,0,1),&nn);
nn *= 1 / pvl;
VectorF cv = contactNormal;
cv -= nn * mDot(nn,cv);
pv -= cv * mDot(pv,cv);
pvl = pv.len();
}and change it to
//if (pvl) {
// VectorF nn;
// mCross(pv,VectorF(0,0,1),&nn);
// nn *= 1 / pvl;
// VectorF cv = contactNormal;
// cv -= nn * mDot(nn,cv);
// pv -= cv * mDot(pv,cv);
// pvl = pv.len();
//}
#3
Scroll all the way back up to the top of Player::updateMove() and find
- continued in next post -
07/15/2005 (5:53 pm)
At this point you can "fly" around but there is no way to move up or down except running up the side of the hill so we need to change it so that the player will fly where you are looking.Scroll all the way back up to the top of Player::updateMove() and find
// Update current orientation
if (mDamageState == Enabled) {
F32 prevZRot = mRot.z;
delta.headVec = mHead;
F32 p = move->pitch;
if (p > M_PI) p -= M_2PI;
mHead.x = mClampF(mHead.x + p,mDataBlock->minLookAngle,
mDataBlock->maxLookAngle);
F32 y = move->yaw;
if (y > M_PI) y -= M_2PI;
GameConnection* con = getControllingClient();
if (move->freeLook && ((isMounted() && getMountNode() == 0) ||
(con && !con->isFirstPerson())))
{
mHead.z = mClampF(mHead.z + y,
-mDataBlock->maxFreelookAngle,
mDataBlock->maxFreelookAngle);
}
else
{
mRot.z += y;
// Rotate the head back to the front, center horizontal
// as well if we're controlling another object.
mHead.z *= 0.5;
if (mControlObject)
mHead.x *= 0.5;
}
// constrain the range of mRot.z
while (mRot.z < 0)
mRot.z += M_2PI;
while (mRot.z > M_2PI)
mRot.z -= M_2PI;
delta.rot = mRot;
delta.rotVec.x = delta.rotVec.y = 0;
delta.rotVec.z = prevZRot - mRot.z;
if (delta.rotVec.z > M_PI)
delta.rotVec.z -= M_2PI;
else if (delta.rotVec.z < -M_PI)
delta.rotVec.z += M_2PI;
delta.head = mHead;
delta.headVec -= mHead;
}
MatrixF zRot;
zRot.set(EulerF(0, 0, mRot.z));
// Desired move direction & speed
VectorF moveVec;
F32 moveSpeed;
if (mState == MoveState && mDamageState == Enabled)
{
zRot.getColumn(0,&moveVec);
moveVec *= move->x;
VectorF tv;
zRot.getColumn(1,&tv);
moveVec += tv * move->y;
// Clamp water movement- continued in next post -
#4
Now replace that code block with
07/15/2005 (5:54 pm)
- continue -Now replace that code block with
// Update current orientation
if (mDamageState == Enabled) {
Point3F prevRot = mRot;
delta.headVec = mHead;
F32 p = move->pitch;
if (p > M_PI) p -= M_2PI;
mHead.x = mClampF(mHead.x + p,mDataBlock->minLookAngle,
mDataBlock->maxLookAngle);
F32 y = move->yaw;
if (y > M_PI) y -= M_2PI;
GameConnection* con = getControllingClient();
if (move->freeLook && ((isMounted() && getMountNode() == 0) ||
(con && !con->isFirstPerson())))
{
mHead.z = mClampF(mHead.z + y,
-mDataBlock->maxFreelookAngle,
mDataBlock->maxFreelookAngle);
}
else
{
mRot.x += p;
mRot.z += y;
// Rotate the head back to the front, center horizontal
// as well if we're controlling another object.
mHead.z *= 0.5;
if (mControlObject)
mHead.x *= 0.5;
}
// constrain the range of mRot.z
while (mRot.z < 0)
mRot.z += M_2PI;
while (mRot.z > M_2PI)
mRot.z -= M_2PI;
// constrain the range of mRot.x
if(mRot.x > 1.5706)
mRot.x = 1.5706;
else if(mRot.x < -1.5706)
mRot.x = -1.5706;
delta.rot = mRot;
delta.rotVec = prevRot - mRot;
if (delta.rotVec.z > M_PI)
delta.rotVec.z -= M_2PI;
else if (delta.rotVec.z < -M_PI)
delta.rotVec.z += M_2PI;
delta.head = mHead;
delta.headVec -= mHead;
}
MatrixF xRot, zRot;
xRot.set(EulerF(mRot.x, 0, 0));
zRot.set(EulerF(0, 0, mRot.z));
MatrixF rot;
rot.mul(zRot, xRot);
// Desired move direction & speed
VectorF moveVec;
F32 moveSpeed;
if (mState == MoveState && mDamageState == Enabled)
{
rot.getColumn(0,&moveVec);
moveVec *= move->x;
VectorF tv;
rot.getColumn(1,&tv);
moveVec += tv * move->y;
rot.getColumn(2,&tv);
moveVec += tv * move->z;
// Clamp water movement
#5
and change it to
07/15/2005 (5:57 pm)
Now if you are like me and think that the falling animation looks better for flying around then jump over to Player::pickActionAnimation() and scroll down till you find:if (mContactTimer >= sContactTickTime) {
// Nothing under our feet
action = PlayerData::RootAnim;
}and change it to
if (mContactTimer >= sContactTickTime) {
// Nothing under our feet
action = PlayerData::FallAnim;
}
#6
07/15/2005 (6:11 pm)
Wow nice you should make a resource. What if you didn't always want to fly is there a way to toggle it on and off.
#7
07/15/2005 (7:55 pm)
Was sarcasm part of this resource Matthew? If not then I just read the thread wrong.
#8
I will probably turn it into a resource when I have a spare moment (hah! =). For the resource version I will include toggling it on and off.
Robert,
No...I wasn't trying to be sarcastic...what did I say that came across as sarcastic?
07/15/2005 (11:52 pm)
Treb,I will probably turn it into a resource when I have a spare moment (hah! =). For the resource version I will include toggling it on and off.
Robert,
No...I wasn't trying to be sarcastic...what did I say that came across as sarcastic?
#9
Awsome! I thank you very much for the help. It works great and compiled with no errors.
Seeing how you are an 'Employee' I had another request of sorts. I see that Torque releases Tools and Starter Kits for sale to augment TGE, do they also sell these coding mods as well? I would pay for CC's and H files that would allow me to fly, jetpack, god view, god mode, flying vehicle, etc.. If not could you have them put it together? It would save all of us Noobes alot of time and I would be the first to buy them. Thanks!
Sam,
I tried yours first and was able to wittle the origianal 54 errrors down to two. The jetEmitter = NULL; AND jetEmitterID = 0; both came up as undefined so I went with Mathews hack instead. Thanks so much for the imput though.
07/16/2005 (3:35 am)
Mattew,Awsome! I thank you very much for the help. It works great and compiled with no errors.
Seeing how you are an 'Employee' I had another request of sorts. I see that Torque releases Tools and Starter Kits for sale to augment TGE, do they also sell these coding mods as well? I would pay for CC's and H files that would allow me to fly, jetpack, god view, god mode, flying vehicle, etc.. If not could you have them put it together? It would save all of us Noobes alot of time and I would be the first to buy them. Thanks!
Sam,
I tried yours first and was able to wittle the origianal 54 errrors down to two. The jetEmitter = NULL; AND jetEmitterID = 0; both came up as undefined so I went with Mathews hack instead. Thanks so much for the imput though.
#10
if (move->freeLook && ((isMounted() && getMountNode() == 0) || (con && !con->is
FirstPerson())))
should be
if (move->freeLook && ((isMounted() && getMountNode() == 0) || (con && !con->isFirstPerson())))
with NO space between "is" &"First"
07/16/2005 (6:31 am)
Also as a side note, the line if (move->freeLook && ((isMounted() && getMountNode() == 0) || (con && !con->is
FirstPerson())))
should be
if (move->freeLook && ((isMounted() && getMountNode() == 0) || (con && !con->isFirstPerson())))
with NO space between "is" &"First"
#11
07/16/2005 (10:58 am)
Matthew I was reffering to this qoute from the original poster. "I would like to also state a general request that if you make a post regarding code to edit the original post instead continually trying to 'add' corrections later on making it harder than hell to read." I guess I just read his message wrong. Sorry
#12
07/17/2005 (12:21 am)
I know it sounded a bit harsh, but was I wrong? Trying to impliment some of the other members code is close to imposible sometimes. They post what they think originally is compete, then five responses later they find out they forgot something then add it in a new post instead of editing the original. That may happen several times making it useable to only a few users who can decyper it. That is why I would love to have all these mods/hacks in CC and H files to just slap in. Yes I know, that may sound great...but I don't need to sound like an ass saying it, and for that I apologize.
#13
07/17/2005 (3:34 am)
I 2 would like to know how to fix this to turn on and off. :) great job by the way :)
#14
07/17/2005 (2:29 pm)
How would you make it so you can swim? would it be that the flying script would activate at water level then de-activated out of it or something?
#16
07/19/2005 (10:53 am)
Kingdom hearts was awesome with the flying. it would be cool to have a flying fps.
#17
08/09/2005 (4:52 am)
Matt, if this works, you will be my new hero. We're working on some machinima animation for mtv2 (15 sec shorts they call interstitials) for part of Video Mods. We use torque for machinima and need a character to fly somewhat like superman (a cyborg girl, cause, that's how cyborg girl's ...fly you know).
#18
I have the arrow keys assigned to left and right panning left and right and up and down moving forward and back. I also have it set up so that when the ctrl key is held down in conjunction with the arrow keys, the left and right arrows cause the camera to strafe. I want the up and down arrows to strafe up and down, but I can't get it to work...it uses $mvUpAction and $mvDownAction to cause the strafing (which does work; I tested it on the actual camera object). Is there any way to make the player object aknowledge these variables?
11/09/2005 (8:53 pm)
I've implemented this as a camera that performs collision detection and it works great; there is just one thing I'm wondering, however:I have the arrow keys assigned to left and right panning left and right and up and down moving forward and back. I also have it set up so that when the ctrl key is held down in conjunction with the arrow keys, the left and right arrows cause the camera to strafe. I want the up and down arrows to strafe up and down, but I can't get it to work...it uses $mvUpAction and $mvDownAction to cause the strafing (which does work; I tested it on the actual camera object). Is there any way to make the player object aknowledge these variables?
#19
11/14/2005 (10:37 am)
I changed my code in player.cc, recompiled Torque.sln in visual studio.net and then tried out example.fps, but nothing seemed to have changed - have I made some hideous mistake?
#20
11/14/2005 (1:32 pm)
Are you sure you are running the right executable?
Torque Owner Sam Guffey
Its my jetpack code for TGE 1.3.