| | |
| | | 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; |
| | |
| | | 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] |
| | |
| | | { |
| | | rb = GetComponent<Rigidbody2D>(); |
| | | touchingCol = rb.GetComponent<BoxCollider2D>(); |
| | | //touchingCol = rb.GetComponent<CapsuleCollider2D>(); |
| | | animator = rb.GetComponent<Animator>(); |
| | | animator_rotor = rotorGO.GetComponent<Animator>(); |
| | | } |
| | |
| | | |
| | | 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; |
| | | } |
| | | |