Guest User

HP2 AutoJump Code

a guest
Feb 9th, 2021
51
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. APlayerPawn* PPawn = Cast<APlayerPawn>(this);
  2.         if( PPawn && PPawn->bAutoJump )
  3.         {
  4.             static float MinAutoJumpCos = 0.25f;
  5.             static float AutoJumpThreshold = 10.f;
  6.  
  7.             // Check whether center has crossed a ledge.
  8.             FVector FootDel = FVector(0,0,-CollisionHeight);
  9.             FVector SubFootDel = FVector(0,0,-CollisionHeight-4.f);
  10.             if( !bZeroMove && GetLevel()->SingleLineCheck( Hit, this, Location + FootDel + Down, Location, TRACE_AllBlocking | TRACE_StopAtFirstHit) )
  11.             {
  12.                 // Find exact location of ledge.
  13.                 FVector Back = Location - AccelDir * (CollisionRadius*1.5f);
  14.                 if( !GetLevel()->SingleLineCheck( Hit, this, Back + SubFootDel, Location + SubFootDel, TRACE_AllBlocking | TRACE_StopAtFirstHit) )
  15.                 {
  16.                     FLOAT Cos = Hit.Normal | AccelDir;
  17.                     if( Cos > MinAutoJumpCos )
  18.                     {
  19.                         // Crossed ledge this tick. See whether we'd really fall on ledge edge.
  20.                         // Move player out to ledge location.
  21.                         FLOAT t = Hit.Time;
  22.                         FVector EdgeLoc = Back * t + Location * (1.f-t);
  23.  
  24.                         // Find where we fall, and where we jump.
  25.                         FVector Start = EdgeLoc + AccelDir * (CollisionRadius*1.5f/Cos);
  26.                         Predict( Hit, this, Start, Velocity, Extent, 2.f );
  27.                         FVector Fall = Hit.Location;
  28.  
  29.                         Predict( Hit, this, EdgeLoc, Velocity + FVector(0,0,JumpZ), Extent, 2.f );
  30.                         FVector Jump = Hit.Location;
  31.  
  32.                         if( Jump.Z - Fall.Z > AutoJumpThreshold )
  33.                         {
  34.                             // Jumping is better.
  35.                             // Move back to edge location, then jump.
  36.                             GetLevel()->MoveActor(this, EdgeLoc - Location, Rotation, Hit);
  37.                             PPawn->eventDoJump(1.f);
  38.                             remainingTime += timeTick * t;
  39.                             physFalling(remainingTime, Iterations);
  40.                             return;
  41.                         }
  42.                     }
  43.                 }
  44.             }
  45.         }
RAW Paste Data