From 620932056c4501706e7afdf93b0185a9ea70e4a0 Mon Sep 17 00:00:00 2001 From: miepzerino <o.skotnik@gmail.com> Date: Sat, 23 Dec 2023 01:59:24 +0000 Subject: [PATCH] Fixed drilling, touchingdirections and ruleTile tiles --- Assets/Scripts/TouchingDirections.cs | 52 ++++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 40 insertions(+), 12 deletions(-) diff --git a/Assets/Scripts/TouchingDirections.cs b/Assets/Scripts/TouchingDirections.cs index 4a26280..08bf06c 100644 --- a/Assets/Scripts/TouchingDirections.cs +++ b/Assets/Scripts/TouchingDirections.cs @@ -5,22 +5,24 @@ public class TouchingDirections : MonoBehaviour { public ContactFilter2D castFilter; - public float groundDistance = 0.05f; - public float wallDistance = 0.2f; + public float groundDistance = 0.01f; + public float wallDistance = 0.01f; public float ceilingDistance = 0.05f; - private Vector2 wallCheckDirection => gameObject.transform.localScale.x > 0 ? Vector2.right : Vector2.left; + //private Vector2 wallCheckDirection => gameObject.transform.localScale.x > 0 ? Vector2.right : Vector2.left; Rigidbody2D rb; public GameObject rotorGO; BoxCollider2D touchingCol; + //CapsuleCollider2D touchingCol; Animator animator; Animator animator_rotor; - RaycastHit2D[] groundHits = new RaycastHit2D[5]; - RaycastHit2D[] wallHits = new RaycastHit2D[5]; - RaycastHit2D[] ceilingHits = new RaycastHit2D[5]; + public RaycastHit2D[] groundHits = new RaycastHit2D[5]; + public RaycastHit2D[] wallHitsRight = new RaycastHit2D[5]; + public RaycastHit2D[] wallHitsLeft = new RaycastHit2D[5]; + public RaycastHit2D[] ceilingHits = new RaycastHit2D[5]; [SerializeField] private bool _isGrounded; @@ -37,14 +39,27 @@ } [SerializeField] - private bool _isAtWall; + private bool _isAtWallLeft; - public bool IsAtWall + public bool IsAtWallLeft { - get { return _isAtWall; } + get { return _isAtWallLeft; } set { - _isAtWall = value; + _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); } @@ -64,12 +79,19 @@ } } - + public bool IsAtWall + { + get + { + return IsAtWallLeft || IsAtWallRight; + } + } void Awake() { rb = GetComponent<Rigidbody2D>(); touchingCol = rb.GetComponent<BoxCollider2D>(); + //touchingCol = rb.GetComponent<CapsuleCollider2D>(); animator = rb.GetComponent<Animator>(); animator_rotor = rotorGO.GetComponent<Animator>(); } @@ -81,8 +103,14 @@ void FixedUpdate() { + + //int contactsAmount = touchingCol.GetContacts(contacts); + //Debug.Log("contactsAmount: " + contactsAmount); IsGrounded = touchingCol.Cast(Vector2.down, castFilter, groundHits, groundDistance) > 0; - IsAtWall = touchingCol.Cast(wallCheckDirection, castFilter, wallHits, wallDistance) > 0; + IsAtWallLeft = touchingCol.Cast(Vector2.left, castFilter, wallHitsLeft, wallDistance) > 0; + IsAtWallRight = touchingCol.Cast(Vector2.right, castFilter, wallHitsRight, wallDistance) > 0; IsAtCeiling = touchingCol.Cast(Vector2.up, castFilter, ceilingHits, ceilingDistance) > 0; } + + //TODO getTileForDrillHere? } -- Gitblit v1.9.3