Platformer Wall Hit Checker
This component is used to check if a GameObject
can be considered colliding with walls.
You can configure any of the 6 points of detection through inspector. The points are:
Upper Right
Upper Left
Center Right
Center Left
Lower Right
Lower Left
What it Requires
Through Unity’s inspector you will need to inform what layers of your project should be considered wall.
A Collider2D
is required. It might be a BoxCollider2D
, a CapsuleCollider2D
or even a CircleCollider2D
. You can directly
specify one (pretty handy in case you are using multiple colliders). If no Collider2D
is provided the component will try finding one.
Important
If you are working with multiple colliders be sure to specify one. Otherwise the wrong one might be used instead.
What it Implements
Interface |
|
What it Provides
Properties
You can directly access the public properties listed below and benefit from its information.
public bool HittingWall;
public WallHitData Data;
Events
You can add listeners through code or inspector to be updated every physics update about the
GameObject
being or not hitting walls.
public UnityEvent<WallHitData> WallHitDataUpdate;
Note
If you are not familiar on how to use Unity Events check out the oficial docs .
Checkout what is the WallHitData composed of for more information about how it can be usefull to you.
Seeks For
Nothing.
WallHitData
namespace Handy2DTools.CharacterController.Checkers
{
public class WallHitData
{
/// <summary>
/// If hitting any walls
/// </summary>
public bool hittingAnyWall = false;
/// <summary>
/// True if hitting any wall to the left
/// </summary>
public bool leftHitting = false;
/// <summary>
///
/// </summary>
public bool rightHitting = false;
/// <summary>
/// True if hitting a wall with the top right corner
/// </summary>
public bool upperRight = false;
/// <summary>
/// The top right corner hit angle
/// </summary>
public float upperRightHitAngle;
/// <summary>
/// True if hitting a wall with the lower right corner
/// </summary>
public bool lowerRight = false;
/// <summary>
/// The lower right corner hit angle
/// </summary>
public float lowerRightHitAngle;
/// <summary>
/// True if hitting a wall with the center right checker
/// </summary>
public bool centerRight = false;
/// <summary>
/// The center right hit angle
/// </summary>
public float centerRightHitAngle;
/// <summary>
/// True if hitting a wall with the top left corner
/// </summary>
public bool upperLeft = false;
/// <summary>
/// The top left corner hit angle
/// </summary>
public float upperLeftHitAngle;
/// <summary>
/// True if hitting a wall with the lower left corner
/// </summary>
public bool lowerLeft = false;
/// <summary>
/// The lower left corner hit angle
/// </summary>
public float lowerLeftHitAngle;
/// <summary>
/// True if hitting a wall with the center left checker
/// </summary>
public bool centerLeft = false;
/// <summary>
/// The center left hit angle
/// </summary>
public float centerLeftHitAngle;
}
}