Game Development Community

Air Control/Jets help please

by Alexander Brown · in Torque Game Engine · 12/04/2006 (8:42 pm) · 7 replies

Ive followed this resource to the "T" (jetting and aircontrol):

http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=11314)

However now ive encountered a problem which i cant seem to figure out.

The problem is with the "aircontrol", where it has one value for both forward and side to side. What im wanting is to have the side to side be more powerful then the forward thrust, allowing for easier strafing while jetting at high speeds. However no matter what ive tried with either the X or Y move coordinates that relate to the aircontrol, it always ends up affecting both forward and side to side thrust. I know a bit about code however im still really new with torque script, so im not too sure on what id need to do to set different integers for aircontrol or even how to have aircontrol recognize the difference from "forward" or "strafe" keys.

If anyone could help, it would be greatly appreciated

#1
12/04/2006 (11:03 pm)
In this section of code in the file player.cc the movement speed is clamped:

// Clamp water movement
      if (move->y > 0)
      {
         if( mWaterCoverage >= 0.9 )
            moveSpeed = getMax(mDataBlock->maxUnderwaterForwardSpeed * move->y,
                               mDataBlock->maxUnderwaterSideSpeed * mFabs(move->x));
         else
         {
            moveSpeed = getMax(mDataBlock->maxForwardSpeed * move->y,
                               mDataBlock->maxSideSpeed * mFabs(move->x));
         }
      }
      else
      {
         if( mWaterCoverage >= 0.9 )
            moveSpeed = getMax(mDataBlock->maxUnderwaterBackwardSpeed * mFabs(move->y),
                               mDataBlock->maxUnderwaterSideSpeed * mFabs(move->x));
         else
            moveSpeed = getMax(mDataBlock->maxBackwardSpeed * mFabs(move->y),
                               mDataBlock->maxSideSpeed * mFabs(move->x));
      }

One way of solving your problem would be to modify it a bit. Before doing so it is important to note one thing. The Move object's x and y fields have nothing to do with the game world. That is to say that if you have a positive x value then the player pressed right, a positive y value means forward, a negative y value means backward, and a negative x value means left.

Using this information you can adjust the clamped movement speed when the player is strafing. To do so you could add the following condition into the above mentioned code:

else if(Move.x != 0) //This means we are strafing.
{
  if( mWaterCoverage >= 0.9 )
  {
    moveSpeed = getMax(mDataBlock->maxUnderwaterForwardSpeed * move->y,
                                       mDataBlock->maxUnderwaterSideSpeed * mFabs(move->x));
  }
  else
  {
    moveSpeed = getMax(mDataBlock->maxForwardSpeed * move->y,
                                        mDataBlock->maxSideSpeed * MODIFIER * mFabs(move->x));
   }
}
*The variable MODIFIER will be how much more control you would like the player to have when they are strafing.

As the code stands now you will have the added sideSpeed(Strafing) on the ground and in the air. Inorder to make sure they only get this strafing boost when they are in the air you could wrap the contents of the added conditional statement by a statement like this:

if(!runSurface)
{
  *code inside added condition statement.
}

I wrote this example based off of my knowledge from Torque 1.4.2. If any of the variables I used no longer exist I apologize. While this is probably not the best way to handle the situation, it will hopefully assist you in accomplishing your goal.
#2
12/05/2006 (7:37 am)
Thanks so much that seems to do the trick. I didnt even need to add the !runsurface mainly because i can adjust that with aircontrol and max side speed anyway :)

However for some reason now my mouse cursor wont go away while im in game, oops something i must have touched before doing this :\

Thanks again
#3
12/05/2006 (6:46 pm)
K well doing more testing it didnt seem to do the trick :(
All of that code seems to just adjust the speed while on the ground, once my chracter is in the air it uses the aircontrol for forward and side to side keeping none of the chracteristics i set within that block....sucks :(
#4
12/05/2006 (8:23 pm)
I am not totaly sure how you used what I suggested but this could be what is wrong. The air control section of coding has to modify both side and forward/backward movement the same amount. The reason for this is that it is doing its calculations on the players x and y acceleration inside of the game world. Because of this changing the x value will rarely result in side movement being altered. The effects of changing the x and y acceleration variables depends on the Player's rotation.

I actually tested the code change I suggested and it worked fine for me. I did however have to clean up a few things. Here is the properly written code:

if(move->x != 0) //This means we are strafing.
{
  if(!runSurface && !jumpSurface)
  {
    if( mWaterCoverage >= 0.9 )
    {
      moveSpeed = getMax(mDataBlock->maxUnderwaterForwardSpeed * move->y,
                                         mDataBlock->maxUnderwaterSideSpeed * mFabs(move->x));
    }
    else
    {
      moveSpeed = getMax(mDataBlock->maxForwardSpeed * move->y,
                                          mDataBlock->maxSideSpeed * MODIFIER * mFabs(move->x));
     }
  }
}

This code must be placed after the following code:

if (!isMounted())
      findContact(&runSurface,&jumpSurface,&contactNormal);
if (jumpSurface)
      mJumpSurfaceNormal = contactNormal;

The reason for this is so that we can use the runSurface and jumpSurface variables.
#5
12/06/2006 (1:35 pm)
I posted your most recent suggestion after the mJumpSurfaceNormal = contactNormal; line, and for some reason i still dont get the results you speak of. With aircontrol at 0.3 i get almost no sideways movment, even with the modifier at 200 :(

I should state that i made aircontrol dependant on the mJetting function being true. Thus If i hold W and jet i go forward, once i stop pressing Jet i dont keep gaining speed. Also that means that i must jet to move sideways, however the sidways "thrust" seems like alot less then its forward counterpart, and thats why i was looking for help with this problem.

Im not sure if the mJetting requirement for aircontrol would interfere with your solution, but i dont see how it would since ur changing X before it even interacts with aircontrol.

If its any help here is my player.cc: greywolf.derelict.us/player.cc
#6
12/06/2006 (4:07 pm)
YAY i got it :D

i add this:

if ( mDataBlock->airControl > 0.0 && move->x != 0 )
mDataBlock->airControl = 0.4;
else
mDataBlock->airControl = 0.15;

below this:

if (!inLiquid && mDataBlock->airControl > 0.0f && moveVec.x != 0 && moveVec.y != 0)

and added if mJetting after the else above the 2nd if statement

And that made the thrust going forward .15 while side to side is .4 :D

Thank you so much Joshua for all your help, without it i wouldnt have figured this out.

Thank you so much for all the help :D

I owe you a beer
#7
12/06/2006 (7:05 pm)
I am glad that I could help. It is good to hear that you got everything working as desired.