miepzerino
2023-12-14 d8e9a15a36f5285e4c635f0e1044c5bae1cf4f2f
Added more touching directions
4 files modified
82 ■■■■■ changed files
Assets/Characters/Player/Player.prefab 40 ●●●●● patch | view | raw | blame | history
Assets/Scripts/AnimationStrings.cs 3 ●●●●● patch | view | raw | blame | history
Assets/Scripts/PlayerController.cs 2 ●●●●● patch | view | raw | blame | history
Assets/Scripts/TouchingDirections.cs 37 ●●●●● patch | view | raw | blame | history
Assets/Characters/Player/Player.prefab
@@ -122,6 +122,7 @@
  - component: {fileID: 3884295854780712968}
  - component: {fileID: 2451348752795735853}
  - component: {fileID: 5338311196462064651}
  - component: {fileID: 3829651782493779324}
  m_Layer: 0
  m_Name: Player
  m_TagString: Untagged
@@ -378,8 +379,8 @@
    adaptiveTiling: 0
  m_AutoTiling: 0
  serializedVersion: 2
  m_Size: {x: 0.88, y: 0.95}
  m_EdgeRadius: 0
  m_Size: {x: 0.7205616, y: 0.7178567}
  m_EdgeRadius: 0.12
--- !u!95 &2451348752795735853
Animator:
  serializedVersion: 5
@@ -430,3 +431,38 @@
  groundDistance: 0.05
  rotorGO: {fileID: 1519978218308964847}
  _isGrounded: 1
--- !u!70 &3829651782493779324
CapsuleCollider2D:
  m_ObjectHideFlags: 0
  m_CorrespondingSourceObject: {fileID: 0}
  m_PrefabInstance: {fileID: 0}
  m_PrefabAsset: {fileID: 0}
  m_GameObject: {fileID: 3345854317100013954}
  m_Enabled: 0
  m_Density: 1
  m_Material: {fileID: 0}
  m_IncludeLayers:
    serializedVersion: 2
    m_Bits: 0
  m_ExcludeLayers:
    serializedVersion: 2
    m_Bits: 0
  m_LayerOverridePriority: 0
  m_ForceSendLayers:
    serializedVersion: 2
    m_Bits: 4294967295
  m_ForceReceiveLayers:
    serializedVersion: 2
    m_Bits: 4294967295
  m_ContactCaptureLayers:
    serializedVersion: 2
    m_Bits: 4294967295
  m_CallbackLayers:
    serializedVersion: 2
    m_Bits: 4294967295
  m_IsTrigger: 0
  m_UsedByEffector: 0
  m_UsedByComposite: 0
  m_Offset: {x: 0, y: 0}
  m_Size: {x: 0.829981, y: 0.93356335}
  m_Direction: 0
Assets/Scripts/AnimationStrings.cs
@@ -9,5 +9,8 @@
        internal static string IsFlying = "IsFlying";
        internal static string IsGrounded = "IsGrounded";
        public static string IsAtWall = "IsAtWall";
        public static string IsAtCeiling = "IsAtCeiling";
    }
}
Assets/Scripts/PlayerController.cs
@@ -14,6 +14,7 @@
    Animator animator;
    Animator animator_rotor;
    public GameObject rotorGO;
    TouchingDirections touchingDirections;
    [SerializeField]
    private bool _isMoving;
@@ -60,6 +61,7 @@
        rb = GetComponent<Rigidbody2D>();
        animator = GetComponent<Animator>();
        animator_rotor = rotorGO.GetComponent<Animator>();
        touchingDirections = GetComponent<TouchingDirections>();
    }
    // Start is called before the first frame update
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;
@@ -15,6 +19,8 @@
    Animator animator_rotor;
    RaycastHit2D[] groundHits = new RaycastHit2D[5];
    RaycastHit2D[] wallHits = new RaycastHit2D[5];
    RaycastHit2D[] ceilingHits = new RaycastHit2D[5];
    [SerializeField]
    private bool _isGrounded;
@@ -29,6 +35,35 @@
            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()
@@ -47,5 +82,7 @@
    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;
    }
}