Beg_Productions

Not Full code for make a recoil system

Sep 28th, 2019
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.62 KB | None | 0 0
  1. public class CharacterHandleWeapon : CharacterAbility
  2.     {
  3.         //Recoil, pls work :(     (when you press the A botton the is in use the +1 recoil for teleport the player +1, and when the D botton is pressed is in use the recoilRight for teleport the player -1, according with the animations of the character)
  4.         public Vector3 recoilLeft = Vector3.zero;
  5.         public Vector3 recoilRight = Vector3.zero;
  6.         public Vector3 recoilRight2 = Vector3.zero;
  7.  
  8.         //Drag and drop the world collider here
  9.         public BoxCollider2D worldCollider;
  10.  
  11.         void Update()
  12.         {
  13.  
  14.             if (Input.GetKeyDown(KeyCode.A))
  15.             {
  16.                 recoilRight = recoilLeft;
  17.                 Debug.Log("'A' button");
  18.                 return;
  19.             }
  20.  
  21.             if (Input.GetKeyDown(KeyCode.D))
  22.             {
  23.                 recoilRight = recoilRight2;
  24.                 Debug.Log("'D' button");
  25.                 return;
  26.             }
  27.  
  28.             if (Input.GetKeyDown(KeyCode.W))
  29.             {
  30.                 Debug.Log("'W' button");
  31.                 return;
  32.             }
  33.  
  34.  
  35.         }
  36.  
  37. public virtual void ShootStart()
  38.         {
  39.             // if the Shoot action is enabled in the permissions, we continue, if not we do nothing.  If the player is dead we do nothing.
  40.             if (!AbilityPermitted
  41.             || (CurrentWeapon == null)
  42.             || (_condition.CurrentState != CharacterStates.CharacterConditions.Normal)
  43.             || (_movement.CurrentState == CharacterStates.MovementStates.LadderClimbing))
  44.             {
  45.  
  46.                 return;
  47.             }
  48.  
  49.             //This is where the player will be after the recoil.
  50.             Vector3 positionAfterRecoil = transform.position + recoilRight;
  51. /*
  52.             //If we are outside the left side of the box, snap to the left side of the box
  53.             if (positionAfterRecoil.x < worldCollider.bounds.min.x)
  54.             {
  55.                 positionAfterRecoil.x = worldCollider.bounds.min.x;
  56.             }
  57.             //if we are outside the right side of the box, snap to the right side of the box
  58.             else if (positionAfterRecoil.x > worldCollider.bounds.max.x)
  59.             {
  60.                 positionAfterRecoil.x = worldCollider.bounds.max.x;
  61.             }
  62. */
  63.            
  64.  
  65.             //This is for teleport the player -1 or +1, depenging the values entered on the inspector
  66.             //Move the player to the modified position after recoil
  67.             transform.position = positionAfterRecoil;
  68.  
  69.             Debug.Log(recoilRight);
  70.             CurrentWeapon.WeaponInputStart();
  71.             return;
  72.         }
Advertisement
Add Comment
Please, Sign In to add comment