Game Development Community

Jumping Forward

by Chris "C2" Byars · in Torque Game Engine · 06/13/2006 (6:39 pm) · 8 replies

Is there an easy way to modify the jump function to make you jump forward a distance as well as up, rather than straight up?

#1
06/14/2006 (3:44 am)
Give Player::updateMove() a goooood read (it's huge). Somewhere in it the jump command is processed (some code involving move->trigger[2], which is hard-mapped to jumping) and an impulse vector (up) is calculated. It's just a matter of modifying that bit and adding a forward impulse to the up impulse.
#2
06/14/2006 (4:24 am)
To further explain what Manoel is talking about:

On line 1563 (In TSE player.cpp, I don't have TGE here).

// Acceleration from Jumping
   if (move->trigger[2] && !isMounted() && canJump())
   {

That's where you should start, in updateMove() and merely add to acc.y to get the effect you're looking for.
#3
06/14/2006 (5:44 am)
Right around here, I assume.

F32 dot = mDot(pv,mJumpSurfaceNormal);
         F32 impulse = mDataBlock->jumpForce / mMass;
         if (dot <= 0)
            acc.z += mJumpSurfaceNormal.z * scaleZ * impulse * zSpeedScale;
         else
         {
            acc.x += pv.x * impulse * dot;
            [b]acc.y += pv.y * impulse * dot;[/b]
            acc.z += mJumpSurfaceNormal.z * scaleZ * impulse * zSpeedScale;
         }

To give you an idea, I'm making a game that revolves around the player movement being.. hopping. Hop forward, backward, side to side, rather than walking or running forward/back/sideways, so I'm working to find a way to get this to work. In script you can do it, its just the movement forces aren't very good paired with jumping, for good control/speed.
#4
06/14/2006 (6:27 am)
Try changing acc.y to use the same math as acc.z, and see what happens.

Jumping like you can jump in different directions in Unreal games?
#5
06/14/2006 (6:30 am)
Doing the same math doesn't seem to do anything, or if it does, a very slight difference in direction when jumping on angled surfaces.

I may implement the air control/jump direction resource, I think it might be what needs to be done to get the effect I wish to achieve.
#6
06/14/2006 (6:40 am)
It's just a matter of applying force in the Y direction.
You shouldn't have to implement the air control resource, but good luck to you. :)
#7
06/14/2006 (11:02 am)
Edited: The air control resource + scripting should do everything I need. :)

Only one problem I'm having. I put the jump code into each of the movement functions. However, if you hold more than one movement button down at a time, the jump stops and you just run. What should I do to make it so if a movement key is already being held down, don't call the $mvTriggerCount2++; on the others?
#8
06/14/2006 (1:12 pm)
*rejoices after a ton of rewriting and testing*

Finally got it working flawlessly after working with a hell of a lot of if and else statements. Phew.

$movementSpeed = 1; // m/s

$forwardy = "false";
$backwardy = "false";
$lefty = "false";
$righty = "false";
$isMoving = "false";

function setSpeed(%speed)
{
   if(%speed)
      $movementSpeed = %speed;
}

function moveleft(%val)
{
   if (%val && $isMoving $= "false")
   {
      $mvLeftAction = %val * $movementSpeed;
      $mvTriggerCount2++;
      $isMoving = "true";
      $lefty = "true";
   }
   else if (%val && $isMoving $= "true")
   {
      $mvLeftAction = %val * $movementSpeed;
      $isMoving = "true";
      $lefty = "true";
   }
   else if ($forwardy $= "false" && $righty $= "false" && $backwardy $= "false")
   {
      $mvLeftAction = %val * $movementSpeed;
      $isMoving = "false";
      $mvTriggerCount2++;
      $lefty = "false";
   }
   else
   {
      $mvLeftAction = %val * $movementSpeed;
      $lefty = "false";
   }
}

function moveright(%val)
{
   if (%val && $isMoving $= "false")
   {
      $mvRightAction = %val * $movementSpeed;
      $mvTriggerCount2++;
      $isMoving = "true";
      $righty = "true";		
   }
   else if (%val && $isMoving $= "true")
   {
      $mvRightAction = %val * $movementSpeed;
      $isMoving = "true";
      $righty = "true";	
   }
   else if ($lefty $= "false" && $forwardy $= "false" && $backwardy $= "false")
   {
      $mvRightAction = %val * $movementSpeed;
      $isMoving = "false";
      $mvTriggerCount2++;
      $righty = "false";
   }
   else
   {
      $mvRightAction = %val * $movementSpeed;
      $righty = "false";
   }
}

function moveforward(%val)
{
   if (%val && $isMoving $= "false")
   {
      $mvForwardAction = %val * $movementSpeed;
      $mvTriggerCount2++;
      $isMoving = "true";
      $forwardy = "true";			
   }
   else if (%val && $isMoving $= "true")
   {
      $mvForwardAction = %val * $movementSpeed;
      $isMoving = "true";
      $forwardy = "true";
   }
   else if ($lefty $= "false" && $righty $= "false" && $backwardy $= "false")
   {
      $mvForwardAction = %val * $movementSpeed;
      $isMoving = "false";
      $mvTriggerCount2++;
      $forwardy = "false";
   }
   else
   {
      $mvForwardAction = %val * $movementSpeed;
      $forwardy = "false";
   }
}

function movebackward(%val)
{
   if (%val && $isMoving $= "false")
   {
      $mvBackwardAction = %val * $movementSpeed;
      $mvTriggerCount2++;
      $isMoving = "true";
      $backwardy = "true";		
   }
   else if (%val && $isMoving $= "true")
   {
      $mvBackwardAction = %val * $movementSpeed;
      $isMoving = "true";
      $backwardy = "true";
   }
   else if ($lefty $= "false" && $righty $= "false" && $forwardy $= "false")
   {
      $mvBackwardAction = %val * $movementSpeed;
      $isMoving = "false";
      $mvTriggerCount2++;
      $backwardy = "false";
   }
   else
   {
      $mvBackwardAction = %val * $movementSpeed;
      $backwardy = "false";
   }
}