Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void OnControllerColliderHit(ControllerColliderHit hit){
- //Did we hit a wall? Did we hit it from the side and not from above or below?
- if (!characterController.isGrounded && hit.gameObject.tag == "Wall" && !AlmostEqual(hit.normal,transform.up,0.1f) && !AlmostEqual(hit.normal,-transform.up,0.1f)) {
- //Is this the same wall we hit before without landing in between?
- if (lastHit == null || !lastHit.gameObject.Equals(hit.gameObject) ) {
- {
- //Save what direction is away from the wall
- forbiddenMove = hit.normal * movementSpeed;
- //Make sure we are allowed to jump again even if we havent touched the ground.
- canWallJump = true;
- //Make sure we are stuck to the wall
- stuckToWall = true;
- //This hit is now considered the "lastHit" so this only can happen once per wall and jump.
- lastHit = hit;
- //is the wall on the players left or right? Tilt the camera that way and play the wall-sound in that speaker
- if (AlmostEqual(transform.right, hit.normal, 1f))
- {
- targetCamTilt = Quaternion.Euler(0, 0, -10);
- sounder.PlayWallSound(-1f);
- }
- else
- {
- targetCamTilt = Quaternion.Euler(0, 0, 10);
- sounder.PlayWallSound(1f);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement