miepzerino
2023-12-23 620932056c4501706e7afdf93b0185a9ea70e4a0
Fixed drilling, touchingdirections and ruleTile tiles

ruleTile tiles were not all from the correct tileSet (some were from the example tileSet)
changed player collision detection to continious
5 files modified
128 ■■■■■ changed files
Assets/Scenes/GameplayScene.unity 24 ●●●●● patch | view | raw | blame | history
Assets/Scripts/PlayerController.cs 37 ●●●●● patch | view | raw | blame | history
Assets/Scripts/TouchingDirections.cs 16 ●●●●● patch | view | raw | blame | history
Assets/TileSets/Palettes/ForestRuleTile.asset 50 ●●●● patch | view | raw | blame | history
TODOs 1 ●●●● patch | view | raw | blame | history
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: []
Assets/Scripts/PlayerController.cs
@@ -85,7 +85,7 @@
    {
        get
        {
            return animator.GetBool(AnimationStrings.canMove) && !PauseMenu.GameIsPaused;
            return animator.GetBool(AnimationStrings.canMove) && !PauseMenu.GameIsPaused && !IsDrilling;
        }
    }
@@ -112,6 +112,8 @@
    }
    private void FixedUpdate()
    {
        if (CanMove)
    {
        if (moveInput.y == 0)
        {
@@ -163,20 +165,22 @@
            //IsDrilling = true;
            Drill(DrillDirection.Down);
        }
        if (touchingDirections.IsGrounded && touchingDirections.IsAtWall && moveInput.x != 0 && !IsDrilling)
            if (touchingDirections.IsGrounded && moveInput.x != 0 && !IsDrilling)
        {
            //IsDrilling = true;
            if (touchingDirections.IsAtWallLeft)
                if (touchingDirections.IsAtWallLeft && moveInput.x < 0)
            {
                Drill(DrillDirection.Left);
            }
            else if (touchingDirections.IsAtWallRight)
                else if (touchingDirections.IsAtWallRight && moveInput.x > 0)
            {
                Drill(DrillDirection.Right);
            }
        }
        }
        if (IsDrilling)
        {
            rb.velocity = Vector2.zero;
            if (timeSinceDrill > drillingTime)
            {
                IsDrilling = false;
@@ -191,8 +195,6 @@
    public void OnMove(InputAction.CallbackContext context)
    {
        if (CanMove)
        {
            moveInput = context.ReadValue<Vector2>();
            IsMoving = moveInput.x != 0;
@@ -200,13 +202,12 @@
            IsFlying = (moveInput.y != 0);
            SetFacingDirection(moveInput);
        }
        else
        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)
        {
            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);
        } else if (drillDirection == DrillDirection.Left || drillDirection == DrillDirection.Right)
        {
            touchingDirections.wallHits[0].collider.GetContacts(contactPoints);
                break;
        }
        CharacterEvents.characterDrill.Invoke(contactPoints[0], drillDirection);
    }
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;
    }
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
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)