From 8139cd89a52559cdd906cd5866dcc55dbd7003a7 Mon Sep 17 00:00:00 2001
From: miepzerino <o.skotnik@gmail.com>
Date: Fri, 15 Dec 2023 20:14:49 +0000
Subject: [PATCH] Merge branch 'release/v_0.0.1'

---
 Assets/Scripts/TouchingDirections.cs |   88 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 88 insertions(+), 0 deletions(-)

diff --git a/Assets/Scripts/TouchingDirections.cs b/Assets/Scripts/TouchingDirections.cs
new file mode 100644
index 0000000..4a26280
--- /dev/null
+++ b/Assets/Scripts/TouchingDirections.cs
@@ -0,0 +1,88 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class TouchingDirections : MonoBehaviour
+{
+    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;
+
+    BoxCollider2D touchingCol;
+    Animator animator;
+    Animator animator_rotor;
+
+    RaycastHit2D[] groundHits = new RaycastHit2D[5];
+    RaycastHit2D[] wallHits = new RaycastHit2D[5];
+    RaycastHit2D[] ceilingHits = new RaycastHit2D[5];
+
+    [SerializeField]
+    private bool _isGrounded;
+
+    public bool IsGrounded
+    {
+        get { return _isGrounded; }
+        set
+        {
+            _isGrounded = value;
+            animator.SetBool(AnimationStrings.Player.isGrounded, value);
+            animator_rotor.SetBool(AnimationStrings.Player.isGrounded, value);
+        }
+    }
+
+    [SerializeField]
+    private bool _isAtWall;
+
+    public bool IsAtWall
+    {
+        get { return _isAtWall; }
+        set
+        {
+            _isAtWall = 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);
+        }
+    }
+
+
+
+    void Awake()
+    {
+        rb = GetComponent<Rigidbody2D>();
+        touchingCol = rb.GetComponent<BoxCollider2D>();
+        animator = rb.GetComponent<Animator>();
+        animator_rotor = rotorGO.GetComponent<Animator>();
+    }
+    // Start is called before the first frame update
+    void Start()
+    {
+
+    }
+
+    void FixedUpdate()
+    {
+        IsGrounded = touchingCol.Cast(Vector2.down, castFilter, groundHits, groundDistance) > 0;
+        IsAtWall = touchingCol.Cast(wallCheckDirection, castFilter, wallHits, wallDistance) > 0;
+        IsAtCeiling = touchingCol.Cast(Vector2.up, castFilter, ceilingHits, ceilingDistance) > 0;
+    }
+}

--
Gitblit v1.9.3