Platformer Wall Grab
This component is used to perform platfomer wall grabs.
Category
Learnable |
What it Implements
Interface |
Setup
Feeding Dependencies
Below you will find what you should feed this component with and how. You can always do it by directly accessing its methods or having components wich provide what they need and mark this component to seek for them through the inspector window.
Movement Performer
In order to move on the Y while performing, this component will need a platformer movement performer.
You can directly set one: slide.MovementPerformer = movementPerformer
. As long as movementPerformer implements the
IPlatformerMovementPerformer interface.
Or you can mark the component to seek for an
IPlatformerMovementPerformer as long as it has some component wich implements
it among its GameObject
other components.
Wall Hit Data
This component needs to know if its GameObject
can be considered hitting walls to evaluate if it can grab or not on a wall.
You can use the UpdateWallHitData(WallHitData newWallHitData)
method every update or mark the component to seek for an
IPlatformerWallHitDataProvider as long as it has some component wich implements
it among its GameObject
other components. Our Platformer Wall Hit Checker implements it.
Usage
Requesting a wall grab is different from requesting jumps, slides or other abilities that are requested through user input. So, instead of relying on handlers it will be your responsibility to evaluate when your code should request a wall grab and the component will start performing accordingly.
Direct approach
PlatformerWallGrab wallGrab;
float verticalDirectionSign;
float horizontalDirectionSign;
void Awake()
{
wallGrab = GetComponent<PlatformerWallGrab>();
}
void Update()
{
verticalDirectionSign = MyWayOfDetectingVerticalDirection(); // -1 down, 1 up
horizontalDirectionSign = MyWayOfDetectingHorizontalDirection(); // -1 left, 1 right
if (ConditionToRequestWallGrab)
{
wallGrab.Request(horizontalDirectionSign);
}
}
void FixedUpdate()
{
if (wallGrab.Performing)
{
wallGrab.Perform(verticalDirectionSign); // or leave arguments blank for no movement.
}
}
Requesting wall grabs using IPlatformerWallGrabPerformer interface
IPlatformerWallGrabPerformer wallGrabPerformer;
float verticalDirectionSign;
float horizontalDirectionSign;
void Awake()
{
wallGrabPerformer = GetComponent<IPlatformerWallGrabPerformer>();
}
void Update()
{
verticalDirectionSign = MyWayOfDetectingVerticalDirection(); // -1 down, 1 up
horizontalDirectionSign = MyWayOfDetectingHorizontalDirection(); // -1 left, 1 right
if (ConditionToRequestWallGrab)
{
wallGrabPerformer.Request(horizontalDirectionSign);
}
}
void FixedUpdate()
{
if (wallGrabPerformer.Performing)
{
wallGrabPerformer.Perform(verticalDirectionSign); // or leave arguments blank for no movement.
}
}
Listening to IPlatformerWallGrabPerformer interface events
IPlatformerSlidePerformer wallGrabPerformer;
void Awake()
{
wallGrabPerformer = GetComponent<IPlatformerSlidePerformer>();
}
void Start()
{
wallGrabPerformer?.WallGrabUpdate.AddListener(OnWallGrabUpdate);
}
void OnDisable()
{
wallGrabPerformer?.WallGrabUpdate.RemoveListener(OnWallGrabUpdate);
}
void OnWallGrabUpdate(bool isSliding)
{
// Your logic
}
Note
You can also use the direct approach to listen to the events.
The perform approach
This component cannot autoperform.
Available Properties
public bool Performing { get; }
public IPlatformerMovementPerformer MovementPerformer { get; set; }
public IPlatformerWallHitDataProvider WallHitDataProvider { get; set; }
Available Methods
/// <summary>
/// Evaluates if can start the wall grab process. If so Perform() should be called each physics update.
/// </summary>
public void Request(float movementDirectionSign)
/// <summary>
/// Should be called on Fixed (Physics) Update. If direction passed as 0 means no movement.
/// Note that gravity can still affect the RigidBody2D
/// </summary>
/// <param name="directionSign">The direction sign to move. -1 down, 1 up</param>
public void Perform(float directionSign = 0)
/// <summary>
/// Stops Wall slide progress.
/// </summary>
public void Stop()
/// <summary>
/// Call this to update wall hit data.
/// </summary>
/// <param name="newWallGrab"></param>
public void UpdateWallHitData(WallHitData newWallHitData)