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/TileSets/Palettes/ForestRuleTile.asset |   50 ++++++------
 Assets/Scripts/PlayerController.cs            |  131 +++++++++++++++++---------------
 TODOs                                         |    1 
 Assets/Scenes/GameplayScene.unity             |   24 ++++++
 Assets/Scripts/TouchingDirections.cs          |   16 ++-
 5 files changed, 130 insertions(+), 92 deletions(-)

diff --git a/Assets/Scenes/GameplayScene.unity b/Assets/Scenes/GameplayScene.unity
index 42df583..c2d7705 100644
--- a/Assets/Scenes/GameplayScene.unity
+++ b/Assets/Scenes/GameplayScene.unity
@@ -4991,6 +4991,30 @@
       propertyPath: m_Name
       value: Player
       objectReference: {fileID: 0}
+    - target: {fileID: 3884295854780712968, guid: c220ec455fce341408d66d880b464cad, type: 3}
+      propertyPath: m_Size.x
+      value: 0.7
+      objectReference: {fileID: 0}
+    - target: {fileID: 3884295854780712968, guid: c220ec455fce341408d66d880b464cad, type: 3}
+      propertyPath: m_Size.y
+      value: 0.7
+      objectReference: {fileID: 0}
+    - target: {fileID: 3884295854780712968, guid: c220ec455fce341408d66d880b464cad, type: 3}
+      propertyPath: m_EdgeRadius
+      value: 0
+      objectReference: {fileID: 0}
+    - target: {fileID: 4941032555966952991, guid: c220ec455fce341408d66d880b464cad, type: 3}
+      propertyPath: m_CollisionDetection
+      value: 1
+      objectReference: {fileID: 0}
+    - target: {fileID: 5338311196462064651, guid: c220ec455fce341408d66d880b464cad, type: 3}
+      propertyPath: wallDistance
+      value: 0.02
+      objectReference: {fileID: 0}
+    - target: {fileID: 5338311196462064651, guid: c220ec455fce341408d66d880b464cad, type: 3}
+      propertyPath: groundDistance
+      value: 0.02
+      objectReference: {fileID: 0}
     m_RemovedComponents: []
     m_RemovedGameObjects: []
     m_AddedGameObjects: []
diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs
index 1ab8309..ed9f0d7 100644
--- a/Assets/Scripts/PlayerController.cs
+++ b/Assets/Scripts/PlayerController.cs
@@ -85,7 +85,7 @@
     {
         get
         {
-            return animator.GetBool(AnimationStrings.canMove) && !PauseMenu.GameIsPaused;
+            return animator.GetBool(AnimationStrings.canMove) && !PauseMenu.GameIsPaused && !IsDrilling;
         }
     }
 
@@ -113,70 +113,74 @@
 
     private void FixedUpdate()
     {
-        if (moveInput.y == 0)
+        if (CanMove)
         {
-            if (rb.velocity.y <= maxFallSpeed)
+            if (moveInput.y == 0)
             {
-                // max fall speed, dont accelerate more
-                rb.velocity = new Vector2(moveInput.x * moveSpeed, maxFallSpeed);
+                if (rb.velocity.y <= maxFallSpeed)
+                {
+                    // max fall speed, dont accelerate more
+                    rb.velocity = new Vector2(moveInput.x * moveSpeed, maxFallSpeed);
+                }
+                else
+                {
+                    // normal fall
+                    rb.velocity = new Vector2(moveInput.x * moveSpeed, rb.velocity.y);
+                }
             }
             else
             {
-                // normal fall
-                rb.velocity = new Vector2(moveInput.x * moveSpeed, rb.velocity.y);
+                if (rb.velocity.y < 0 && moveInput.y > 0)
+                {
+                    // falling but moving upwards
+                    rb.velocity = new Vector2(moveInput.x * moveSpeed, (moveInput.y * moveSpeed) + rb.velocity.y);
+                }
+                else
+                {
+                    // moving upwards no falling
+                    rb.velocity = new Vector2(moveInput.x * moveSpeed, (moveInput.y * moveSpeed));
+                }
             }
-        }
-        else
-        {
-            if (rb.velocity.y < 0 && moveInput.y > 0)
+            if (touchingDirections.IsGrounded)
             {
-                // falling but moving upwards
-                rb.velocity = new Vector2(moveInput.x * moveSpeed, (moveInput.y * moveSpeed) + rb.velocity.y);
+                if (maxFallSpeedCurrent < maxFallSpeedDamge)
+                {
+                    TakeFallDamage(Math.Abs((int)maxFallSpeedCurrent));
+                    maxFallSpeedCurrent = 0;
+                }
             }
-            else
-            {
-                // moving upwards no falling
-                rb.velocity = new Vector2(moveInput.x * moveSpeed, (moveInput.y * moveSpeed));
-            }
-        }
-        if (touchingDirections.IsGrounded)
-        {
-            if (maxFallSpeedCurrent < maxFallSpeedDamge)
-            {
-                TakeFallDamage(Math.Abs((int)maxFallSpeedCurrent));
-                maxFallSpeedCurrent = 0;
-            }
-        }
-        else if (IsFlying)
-        {
-            maxFallSpeedCurrent = rb.velocity.y;
-        }
-        else
-        {
-            if (maxFallSpeedCurrent > rb.velocity.y)
+            else if (IsFlying)
             {
                 maxFallSpeedCurrent = rb.velocity.y;
             }
-        }
-        if (touchingDirections.IsGrounded && moveInput.y < 0 && !IsDrilling)
-        {
-            //IsDrilling = true;
-            Drill(DrillDirection.Down);
-        }
-        if (touchingDirections.IsGrounded && touchingDirections.IsAtWall && moveInput.x != 0 && !IsDrilling)
-        {
-            //IsDrilling = true;
-            if (touchingDirections.IsAtWallLeft)
+            else
             {
-                Drill(DrillDirection.Left);
+                if (maxFallSpeedCurrent > rb.velocity.y)
+                {
+                    maxFallSpeedCurrent = rb.velocity.y;
+                }
             }
-            else if (touchingDirections.IsAtWallRight)
+            if (touchingDirections.IsGrounded && moveInput.y < 0 && !IsDrilling)
             {
-                Drill(DrillDirection.Right);
+                //IsDrilling = true;
+                Drill(DrillDirection.Down);
+            }
+
+            if (touchingDirections.IsGrounded && moveInput.x != 0 && !IsDrilling)
+            {
+                if (touchingDirections.IsAtWallLeft && moveInput.x < 0)
+                {
+                    Drill(DrillDirection.Left);
+                }
+                else if (touchingDirections.IsAtWallRight && moveInput.x > 0)
+                {
+                    Drill(DrillDirection.Right);
+                }
             }
         }
         if (IsDrilling)
         {
+            rb.velocity = Vector2.zero;
             if (timeSinceDrill > drillingTime)
             {
                 IsDrilling = false;
@@ -191,22 +195,19 @@
 
     public void OnMove(InputAction.CallbackContext context)
     {
-        if (CanMove)
-        {
-            moveInput = context.ReadValue<Vector2>();
+        moveInput = context.ReadValue<Vector2>();
 
-            IsMoving = moveInput.x != 0;
+        IsMoving = moveInput.x != 0;
 
-            IsFlying = (moveInput.y != 0);
+        IsFlying = (moveInput.y != 0);
 
-            SetFacingDirection(moveInput);
-
-        }
-        else
+        SetFacingDirection(moveInput);
+        if (IsDrilling)
         {
             IsMoving = false;
             IsFlying = false;
-            moveInput = Vector2.zero;
+            //moveInput = Vector2.zero;
+
         }
     }
 
@@ -214,13 +215,19 @@
     {
         IsDrilling = true;
         ContactPoint2D[] contactPoints = new ContactPoint2D[1];
+        Debug.Log("drillDirection: " + drillDirection.ToString());
         //rb.GetContacts(contactPoints);
-        if (drillDirection == DrillDirection.Down)
+        switch (drillDirection)
         {
-            touchingDirections.groundHits[0].collider.GetContacts(contactPoints);
-        } else if (drillDirection == DrillDirection.Left || drillDirection == DrillDirection.Right)
-        {
-            touchingDirections.wallHits[0].collider.GetContacts(contactPoints);
+            case DrillDirection.Left:
+                touchingDirections.wallHitsLeft[0].collider.GetContacts(contactPoints);
+                break;
+            case DrillDirection.Right:
+                touchingDirections.wallHitsRight[0].collider.GetContacts(contactPoints);
+                break;
+            case DrillDirection.Down:
+                touchingDirections.groundHits[0].collider.GetContacts(contactPoints);
+                break;
         }
         CharacterEvents.characterDrill.Invoke(contactPoints[0], drillDirection);
     }
diff --git a/Assets/Scripts/TouchingDirections.cs b/Assets/Scripts/TouchingDirections.cs
index 6091f02..08bf06c 100644
--- a/Assets/Scripts/TouchingDirections.cs
+++ b/Assets/Scripts/TouchingDirections.cs
@@ -5,8 +5,8 @@
 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;
@@ -15,11 +15,13 @@
     public GameObject rotorGO;
 
     BoxCollider2D touchingCol;
+    //CapsuleCollider2D touchingCol;
     Animator animator;
     Animator animator_rotor;
 
     public RaycastHit2D[] groundHits = new RaycastHit2D[5];
-    public RaycastHit2D[] wallHits = new RaycastHit2D[5];
+    public RaycastHit2D[] wallHitsRight = new RaycastHit2D[5];
+    public RaycastHit2D[] wallHitsLeft = new RaycastHit2D[5];
     public RaycastHit2D[] ceilingHits = new RaycastHit2D[5];
 
     [SerializeField]
@@ -89,6 +91,7 @@
     {
         rb = GetComponent<Rigidbody2D>();
         touchingCol = rb.GetComponent<BoxCollider2D>();
+        //touchingCol = rb.GetComponent<CapsuleCollider2D>();
         animator = rb.GetComponent<Animator>();
         animator_rotor = rotorGO.GetComponent<Animator>();
     }
@@ -100,9 +103,12 @@
 
     void FixedUpdate()
     {
+
+        //int contactsAmount = touchingCol.GetContacts(contacts);
+        //Debug.Log("contactsAmount: " + contactsAmount);
         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;
+        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;
     }
 
diff --git a/Assets/TileSets/Palettes/ForestRuleTile.asset b/Assets/TileSets/Palettes/ForestRuleTile.asset
index ecfeae9..d13a705 100644
--- a/Assets/TileSets/Palettes/ForestRuleTile.asset
+++ b/Assets/TileSets/Palettes/ForestRuleTile.asset
@@ -154,7 +154,7 @@
   - m_Id: 8
     m_Sprites:
     - {fileID: 68800321, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3}
-    - {fileID: 1328409926, guid: 2dece116af0ca9145ae459928df1a55f, type: 3}
+    - {fileID: 1862643484, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3}
     m_GameObject: {fileID: 0}
     m_MinAnimationSpeed: 1
     m_MaxAnimationSpeed: 1
@@ -226,30 +226,9 @@
     - {x: 1, y: 0, z: 0}
     - {x: 0, y: -1, z: 0}
     m_RuleTransform: 0
-  - m_Id: 12
-    m_Sprites:
-    - {fileID: -1325585479, guid: 2dece116af0ca9145ae459928df1a55f, type: 3}
-    m_GameObject: {fileID: 0}
-    m_MinAnimationSpeed: 1
-    m_MaxAnimationSpeed: 1
-    m_PerlinScale: 0.5
-    m_Output: 0
-    m_ColliderType: 1
-    m_RandomTransform: 0
-    m_Neighbors: 0100000001000000020000000100000001000000010000000100000001000000
-    m_NeighborPositions:
-    - {x: 0, y: 1, z: 0}
-    - {x: 1, y: 0, z: 0}
-    - {x: 1, y: 1, z: 0}
-    - {x: -1, y: 0, z: 0}
-    - {x: 0, y: -1, z: 0}
-    - {x: -1, y: 1, z: 0}
-    - {x: -1, y: -1, z: 0}
-    - {x: 1, y: -1, z: 0}
-    m_RuleTransform: 0
   - m_Id: 13
     m_Sprites:
-    - {fileID: 1290617244, guid: 2dece116af0ca9145ae459928df1a55f, type: 3}
+    - {fileID: 956194596, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3}
     m_GameObject: {fileID: 0}
     m_MinAnimationSpeed: 1
     m_MaxAnimationSpeed: 1
@@ -268,9 +247,30 @@
     - {x: -1, y: 1, z: 0}
     - {x: 1, y: 1, z: 0}
     m_RuleTransform: 0
+  - m_Id: 16
+    m_Sprites:
+    - {fileID: -855959738, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3}
+    m_GameObject: {fileID: 0}
+    m_MinAnimationSpeed: 1
+    m_MaxAnimationSpeed: 1
+    m_PerlinScale: 0.5
+    m_Output: 0
+    m_ColliderType: 1
+    m_RandomTransform: 0
+    m_Neighbors: 0100000001000000010000000100000001000000010000000200000001000000
+    m_NeighborPositions:
+    - {x: 0, y: 1, z: 0}
+    - {x: 1, y: 0, z: 0}
+    - {x: -1, y: 0, z: 0}
+    - {x: 0, y: -1, z: 0}
+    - {x: -1, y: -1, z: 0}
+    - {x: 1, y: -1, z: 0}
+    - {x: 1, y: 1, z: 0}
+    - {x: -1, y: 1, z: 0}
+    m_RuleTransform: 0
   - m_Id: 14
     m_Sprites:
-    - {fileID: 1623399786, guid: 2dece116af0ca9145ae459928df1a55f, type: 3}
+    - {fileID: 1598334396, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3}
     m_GameObject: {fileID: 0}
     m_MinAnimationSpeed: 1
     m_MaxAnimationSpeed: 1
@@ -291,7 +291,7 @@
     m_RuleTransform: 0
   - m_Id: 15
     m_Sprites:
-    - {fileID: -889089113, guid: 2dece116af0ca9145ae459928df1a55f, type: 3}
+    - {fileID: 1451081626, guid: 42962cf14c23fee4baaaea0cd52d52e0, type: 3}
     m_GameObject: {fileID: 0}
     m_MinAnimationSpeed: 1
     m_MaxAnimationSpeed: 1
diff --git a/TODOs b/TODOs
index 830c199..203ae72 100644
--- a/TODOs
+++ b/TODOs
@@ -19,4 +19,5 @@
   Generate Tilemap in GameManger with loading screen?
   Tilemap seed
   Save/Load tilemaps
+    maybe save all deleted tiles in an array and destroy them on load? (maybe better than saving all tiles in savefile)
 

--
Gitblit v1.9.3