From 6f2125d2cd1607b8fb70db652607adc84fd9346c Mon Sep 17 00:00:00 2001 From: miepzerino <o.skotnik@gmail.com> Date: Fri, 22 Dec 2023 19:40:59 +0000 Subject: [PATCH] Added drilling function to player --- Assets/Scripts/TouchingDirections.cs | 65 +++++++++++++++++++++++++++++++- 1 files changed, 62 insertions(+), 3 deletions(-) diff --git a/Assets/Scripts/TouchingDirections.cs b/Assets/Scripts/TouchingDirections.cs index cbf8a60..6091f02 100644 --- a/Assets/Scripts/TouchingDirections.cs +++ b/Assets/Scripts/TouchingDirections.cs @@ -6,6 +6,10 @@ { public ContactFilter2D castFilter; public float groundDistance = 0.05f; + public float wallDistance = 0.2f; + public float ceilingDistance = 0.05f; + + //private Vector2 wallCheckDirection => gameObject.transform.localScale.x > 0 ? Vector2.right : Vector2.left; Rigidbody2D rb; public GameObject rotorGO; @@ -14,7 +18,9 @@ Animator animator; Animator animator_rotor; - RaycastHit2D[] groundHits = new RaycastHit2D[5]; + public RaycastHit2D[] groundHits = new RaycastHit2D[5]; + public RaycastHit2D[] wallHits = new RaycastHit2D[5]; + public RaycastHit2D[] ceilingHits = new RaycastHit2D[5]; [SerializeField] private bool _isGrounded; @@ -25,11 +31,59 @@ set { _isGrounded = value; - animator.SetBool(AnimationStrings.Player.IsGrounded, value); - animator_rotor.SetBool(AnimationStrings.Player.IsGrounded, value); + animator.SetBool(AnimationStrings.Player.isGrounded, value); + animator_rotor.SetBool(AnimationStrings.Player.isGrounded, value); } } + [SerializeField] + private bool _isAtWallLeft; + + public bool IsAtWallLeft + { + get { return _isAtWallLeft; } + set + { + _isAtWallLeft = value; + animator.SetBool(AnimationStrings.Player.isAtWall, value); + animator_rotor.SetBool(AnimationStrings.Player.isAtWall, value); + } + } + [SerializeField] + private bool _isAtWallRight; + + public bool IsAtWallRight + { + get { return _isAtWallRight; } + set + { + _isAtWallRight = value; + animator.SetBool(AnimationStrings.Player.isAtWall, value); + animator_rotor.SetBool(AnimationStrings.Player.isAtWall, value); + } + } + + [SerializeField] + private bool _isAtCeiling; + + public bool IsAtCeiling + { + get { return _isAtCeiling; } + set + { + _isAtCeiling = value; + animator.SetBool(AnimationStrings.Player.isAtCeiling, value); + animator_rotor.SetBool(AnimationStrings.Player.isAtCeiling, value); + } + } + + public bool IsAtWall + { + get + { + return IsAtWallLeft || IsAtWallRight; + } + } void Awake() { @@ -47,5 +101,10 @@ void FixedUpdate() { IsGrounded = touchingCol.Cast(Vector2.down, castFilter, groundHits, groundDistance) > 0; + IsAtWallLeft = touchingCol.Cast(Vector2.left, castFilter, wallHits, wallDistance) > 0; + IsAtWallRight = touchingCol.Cast(Vector2.right, castFilter, wallHits, wallDistance) > 0; + IsAtCeiling = touchingCol.Cast(Vector2.up, castFilter, ceilingHits, ceilingDistance) > 0; } + + //TODO getTileForDrillHere? } -- Gitblit v1.9.3