Advertisement
Guest User

Untitled

a guest
Nov 17th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.04 KB | None | 0 0
  1. vector3, bool QA_CheckIfJumpable(double maxPitch = double.max)
  2. {
  3.     // gimpy-ass PM_SlideMove wannabe let's go
  4.     if (floorsector)
  5.     {
  6.         double fas_floorz;
  7.         Sector fas_sector;
  8.        
  9.         [fas_floorz, fas_sector] = floorsector.NextLowestFloorAt(pos.x, pos.y, pos.z, FFCF_3DRESTRICT, MaxStepHeight);
  10.        
  11.         vector3 normal = fas_sector.floorplane.Normal;
  12.         double floorPitch = 90 - atan2(normal.z, (normal.x, normal.y).length());
  13.        
  14.         if (pos.z <= fas_floorz)
  15.         {
  16.             return normal, floorPitch < maxPitch;
  17.         }
  18.     }
  19.    
  20.     return (0, 0, 1), false;
  21. }
  22.  
  23.  
  24. bool QA_CheckJump()
  25. {
  26.     UserCmd cmd = player.cmd;
  27.  
  28.     if (player.onGround && (cmd.buttons & BT_JUMP) && level.IsJumpingAllowed() && !Q_BlockJump)
  29.     {
  30.         double jumpvelz = (JumpZ * 35) / TICRATE;
  31.         double jumpfac  = 0;
  32.  
  33.         // [BC] If the player has the high jump power, double his jump velocity.
  34.         // (actually, pick the best factors from all active items.)
  35.         //
  36.         // I would modify this to add the effective jump bonuses together,
  37.         //  but that'd lead to serious jump height sequence breaks
  38.         for (let p = Inv; p != null; p = p.Inv)
  39.         {
  40.             let pp = PowerHighJump(p);
  41.  
  42.             if (pp)
  43.             {
  44.                 double f = pp.Strength;
  45.                 jumpfac = max(jumpfac, f);
  46.             }
  47.         }
  48.  
  49.         if (jumpfac > 0) { jumpvelz *= jumpfac; }
  50.  
  51.        
  52.         vector3 floornormal;
  53.         bool canjump;
  54.        
  55.         [floornormal, canjump] = QA_CheckIfJumpable(MAXSLOPEPITCH);
  56.         if (!canjump) { return false; }
  57.        
  58.         vector3 newvel = vel;
  59.        
  60.         // Disgusting hack to get what our Z velocity should be
  61.         // Breaks with teleporters, although I guess you could say it's
  62.         //  kinda like portal jumping
  63.         if (Q_GroundTime <= 1)
  64.         {
  65.             newvel.z = Q_LastVel.z - GetGravity();
  66.         }
  67.        
  68.         double speedIntoFloor = -newvel dot floornormal;
  69.         vector3 alignedvel = newvel + (floornormal * speedIntoFloor);
  70.        
  71.         vector3 jumpvector = (0, 0, jumpvelz);
  72.        
  73.         // Going into floor, align velocity to floor
  74.         if ((Q_GroundTime <= 1 && newvel.z <= 0) || speedIntoFloor > 0)
  75.         {
  76.             newvel = alignedvel;
  77.        
  78.             // Angle jump off floor too since we're bunnyhopping
  79.             if (Q_GroundTime <= 1)
  80.             {
  81.                 jumpvector = floornormal * jumpvelz;
  82.             }
  83.         }
  84.        
  85.         newvel = alignedvel + (newvel - alignedvel) * Q_DoubleJumpFactor;
  86.         vel = newvel + jumpvector;
  87.        
  88.         // XY changes always apply to ramp jumps, but Z changes can be disabled
  89.         if (!Q_RampJump)
  90.         {
  91.             vel.z = newvel.z + jumpvelz;
  92.         }
  93.        
  94.         if (!Q_Autohop) { Q_BlockJump  = true; }
  95.         if (!(player.cheats & CF_PREDICTING)) { A_PlaySound("*jump", CHAN_BODY); }
  96.        
  97.         return true;
  98.     }
  99.  
  100.     return false;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement