Air Control
by F.W. Hardijzer · 04/15/2003 (12:04 pm) · 51 comments
Owke, i've struggled with this subject very long, since i needed it for my bunny game,
and now i found out, i will share it with the rest of the world!
so here we go,
first open up player.h and find the lines
then after that, or somewhere else in there add the following line:
lets open player.cc and add some code!
Inside PlayerData::PlayerData() after
then look for void PlayerData::initPersistFields() and after
then we need to make sure that it is sent and retreived on multiplayer connections so find void PlayerData::packData(BitStream* stream) and after
then find void PlayerData::unpackData(BitStream* stream) and after
ok now we got the variable, lets do some real work!
find void Player::updateMove(const Move* move)
and replace
with this:
then all we need to do is tweak one little thing to make sure the player will still fall so find (still in that same function)
then we need to define how much the player should get control in the air, so open up fps/server/scripts/player.cs and in
then you should be able to steer in mid-air :)
YEAH!
if someone finds bugs or errors in this code, please inform me,
if you think i've done something wrong, please inform me too :P
feedback is a must!
and now i found out, i will share it with the rest of the world!
so here we go,
first open up player.h and find the lines
ParticleEmitterData* splashEmitterList[NUM_SPLASH_EMITTERS]; S32 splashEmitterIDList[NUM_SPLASH_EMITTERS];inside the struct PlayerData: public ShapeBaseData
then after that, or somewhere else in there add the following line:
F32 airControl;Ok, thats enough for player.h,
lets open player.cc and add some code!
Inside PlayerData::PlayerData() after
groundImpactShakeDuration = 1.0; groundImpactShakeFalloff = 10.0;add
airControl=0.0f;
then look for void PlayerData::initPersistFields() and after
addField("groundImpactShakeFalloff", TypeF32, Offset(groundImpactShakeFalloff, PlayerData));addaddField("airControl", TypeF32, Offset(airControl,PlayerData));then we need to make sure that it is sent and retreived on multiplayer connections so find void PlayerData::packData(BitStream* stream) and after
stream->write(groundImpactShakeDuration); stream->write(groundImpactShakeFalloff);add
stream->write(airControl);
then find void PlayerData::unpackData(BitStream* stream) and after
stream->read(&groundImpactShakeDuration); stream->read(&groundImpactShakeFalloff);add
stream->read(&airControl);
ok now we got the variable, lets do some real work!
find void Player::updateMove(const Move* move)
and replace
else
mContactTimer++;with this:
else {
mContactTimer++;
//--- by DJMystic ---
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 * mDataBlock->airControl;
if (runSpeed > maxAcc)
runAcc *= maxAcc / runSpeed;
acc += runAcc;
}
//--- end by DJMystic ---
}then all we need to do is tweak one little thing to make sure the player will still fall so find (still in that same function)
if (mBuoyancy > 1.0 || !mVelocity.isZero() || !runSurface)and change it to
if (mBuoyancy > 1.0 || !runSurface)(Yes, i have removed the || !mVelocity.isZero() part :P)
then we need to define how much the player should get control in the air, so open up fps/server/scripts/player.cs and in
datablock PlayerData(LightMaleHumanArmor)somewhere in the end add
airControl=0.3;(0.3 works fine with me, 0 means NO air control, 1 means equal air control as ground control)
then you should be able to steer in mid-air :)
YEAH!
if someone finds bugs or errors in this code, please inform me,
if you think i've done something wrong, please inform me too :P
feedback is a must!
About the author
#2
It's been a pleasure to implement it,
It's been a pleasure to write a resource on it,
But most of all It's been a pleasure to see so many people where looking for it and i'm the one who wrote the resource >:)
GRTZ DJMystic
PS Please no remarks about my failed attempt to be a po
04/15/2003 (2:32 pm)
It's been a pleasure to find out how it worked,It's been a pleasure to implement it,
It's been a pleasure to write a resource on it,
But most of all It's been a pleasure to see so many people where looking for it and i'm the one who wrote the resource >:)
GRTZ DJMystic
PS Please no remarks about my failed attempt to be a po
#3
04/15/2003 (7:43 pm)
works like a charm.. i raised the jump force to 13.3x90 which is pretty much where I wanted it anyways and the movement is much more noticable.. : ) I saw a minor glitch which may be my keys getting stuck or something but the player seemed to move to the right even tho I was not touching that key.. but then I may be sleepy or something.. but the code does work nicely for what I needed.. : ) thanks.. I am also going to look at making a player that swims in some fashion.. so I may use this as a basis for that.. IE player lands in water he goes prone and moves up down left right depending on the key pressed.. : )
#4
If you "ski" you go to fast. But you alreay know that right Mystic! :D
04/15/2003 (8:41 pm)
Bunny hopping.If you "ski" you go to fast. But you alreay know that right Mystic! :D
#6
06/08/2003 (4:53 am)
Very well done :)
#7
I mis-understood what you were trying to do ... so I applied this to my game (which is a standard FPS one).
My main character was actually bunny-hopping. :)
It actually made me laugh ... ;)
Great resource!
Alex
06/23/2003 (7:03 am)
LOL.I mis-understood what you were trying to do ... so I applied this to my game (which is a standard FPS one).
My main character was actually bunny-hopping. :)
It actually made me laugh ... ;)
Great resource!
Alex
#9
08/03/2003 (5:13 am)
Its Really great... but its glitchy underwater, any way to fix that?
#10
I check if we are in liquid first, and if not we can move
Is it in scorched earth? if yes, thats a problem of the level, the waterblock is not high enough, so the lower part of the water is not liquid :P
08/03/2003 (11:03 am)
Shouldn't be glitchy :SI check if we are in liquid first, and if not we can move
Is it in scorched earth? if yes, thats a problem of the level, the waterblock is not high enough, so the lower part of the water is not liquid :P
#11
Gratz! :)
08/31/2003 (8:00 am)
Just wanted to say that this works great. I implemented it as the first change I've ever made to the C++ code and it was very well written - simple to follow and no problems understand what was going on.Gratz! :)
#12
11/21/2003 (8:39 am)
Very nice. well written for us 3d designers who know enough code to be almost dangerous, but not enough to really do anything :P
#13
In the latest HEAD version, the script to edit is now
starter.fps/server/scripts/player.cs
You'll see there's no "datablock PlayerData(LightMaleHumanArmor)" in that script anymore.
Edit "datablock PlayerData(PlayerBody)" instead:
- add the line airControl = 0.3; anywhere in that datablock
- then, for bunnyjumping, set jumpDelay to 0
Everything's ok now ! :)
05/06/2004 (4:53 pm)
UPDATE:In the latest HEAD version, the script to edit is now
starter.fps/server/scripts/player.cs
You'll see there's no "datablock PlayerData(LightMaleHumanArmor)" in that script anymore.
Edit "datablock PlayerData(PlayerBody)" instead:
- add the line airControl = 0.3; anywhere in that datablock
- then, for bunnyjumping, set jumpDelay to 0
Everything's ok now ! :)
#14
I'm trying to modify your resource so that a player can fly.Actually I want a bot to fly.
I set the acc to (0,0,0) to prevent gravity ant the runAcc.z to a nonzero value. The player now floats above the ground but it's only able to move on an XY plane. Any hints on how to correct that ?
TIA
Bruno
05/22/2004 (7:19 pm)
FW,I'm trying to modify your resource so that a player can fly.Actually I want a bot to fly.
I set the acc to (0,0,0) to prevent gravity ant the runAcc.z to a nonzero value. The player now floats above the ground but it's only able to move on an XY plane. Any hints on how to correct that ?
TIA
Bruno
#15
I think this resource would be better for this:
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=4348
05/23/2004 (2:26 am)
@Bruno,I think this resource would be better for this:
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=4348
#16
09/03/2004 (12:23 pm)
Is there anyway to change this so that you can change the amount of control that player has while in water? As of now, my character has no control while jumpin in water...
#17
HTH
Bruno
09/03/2004 (1:18 pm)
Try removing the !inLiquid in the if (!inLiquid && mDataBlock->airControl > 0.0f) { HTH
Bruno
#18
09/04/2004 (8:30 pm)
Thanks, also figured how how to change it when hes in water. woo
#19
09/14/2004 (2:19 am)
This is great. The ease at which this change was implemented is amazing, with a well written set of instructions on how to change it and an engine that allows for such adjustments.
#20
10/10/2004 (9:21 pm)
Excellent resource, thanks DJMysticje. Definately very useful indeed. 
Torque 3D Owner Tom Feni
thanks.. : )