Advertisement
Guest User

Untitled

a guest
May 28th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.05 KB | None | 0 0
  1.         protected void ApplyPhysics(GameTime gameTime)
  2.         {
  3.             float gravitationalConstant = 600;
  4.             float terminalVelocity = 1000;
  5.  
  6.             if (GameState.Avatar.Position.Y > this.Baseline)
  7.             {
  8.                 if (GameState.Avatar.JumpTime == 0)
  9.                 {
  10.                     GameState.Avatar.JumpHeight = GameState.Avatar.Position.Y;
  11.                 }
  12.                 GameState.Avatar.JumpTime += (float)gameTime.ElapsedGameTime.TotalSeconds;
  13.                 if (gravitationalConstant * GameState.Avatar.JumpTime < terminalVelocity)
  14.                 {
  15.                     GameState.Avatar.Position.Y = (float)(GameState.Avatar.JumpHeight - (gravitationalConstant * Math.Pow(GameState.Avatar.JumpTime, 2)) / 2);
  16.                 }
  17.                 else
  18.                 {
  19.                     GameState.Avatar.Position.Y = GameState.Avatar.JumpHeight - terminalVelocity * GameState.Avatar.JumpTime;
  20.                 }
  21.             } else {
  22.                 GameState.Avatar.JumpTime = 0;
  23.             }
  24.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement