Advertisement
movethebongos

OnControllerHit

Aug 22nd, 2017
557
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. void OnControllerColliderHit(ControllerColliderHit hit){
  2.  
  3.     //Did we hit a wall? Did we hit it from the side and not from above or below?
  4.     if (!characterController.isGrounded && hit.gameObject.tag == "Wall" && !AlmostEqual(hit.normal,transform.up,0.1f) && !AlmostEqual(hit.normal,-transform.up,0.1f)) {
  5.  
  6.         //Is this the same wall we hit before without landing in between?
  7.         if (lastHit == null || !lastHit.gameObject.Equals(hit.gameObject) ) {
  8.             {
  9.                 //Save what direction is away from the wall
  10.                 forbiddenMove = hit.normal * movementSpeed;
  11.  
  12.                 //Make sure we are allowed to jump again even if we havent touched the ground.
  13.                 canWallJump = true;
  14.  
  15.                 //Make sure we are stuck to the wall
  16.                 stuckToWall = true;
  17.  
  18.                 //This hit is now considered the "lastHit" so this only can happen once per wall and jump.
  19.                 lastHit = hit;
  20.  
  21.                 //is the wall on the players left or right? Tilt the camera that way and play the wall-sound in that speaker
  22.                 if (AlmostEqual(transform.right, hit.normal, 1f))
  23.                 {
  24.                     targetCamTilt = Quaternion.Euler(0, 0, -10);
  25.                     sounder.PlayWallSound(-1f);
  26.                 }
  27.                 else
  28.                 {
  29.                     targetCamTilt = Quaternion.Euler(0, 0, 10);
  30.                     sounder.PlayWallSound(1f);
  31.                 }
  32.             }
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement