Day 97 — How to Climb up from a Ladder

if (other.tag == "Ledge_Grabber")
{
Player playerController = other.transform.parent.GetComponent<Player>();
if (playerController != null)
{
playerController.transform.parent = this.transform;
playerController.GrabLadderTop(_handPos, this);
}
else
{
Debug.LogError("Can't find Player script");
}
}
private bool _ladderClimb;if (_onLadder == true)
{
float verticalInput = Input.GetAxis("Vertical");
_direction = new Vector3(0, verticalInput, 0);
velocity = _direction * speed;
_anim.SetBool("LadderClimb", true);
if (verticalInput == 0 && _ladderClimb == false)
{
_anim.speed = 0;
}
else
{
_anim.speed = _prevSpeed;
}
}
private LadderTop _activeLadderTop;public void GrabLadderTop(Vector3 handPos, LadderTop currentLadderTop)
{
_controller.enabled = false;
_ladderClimb = true;
_onLadder = false
_anim.SetTrigger("LadderClimbUp");
_anim.SetFloat("Speed", 0.0f);
_activeLadderTop = currentLadderTop;
transform.localPosition = handPos;
}
public void LadderClimbComplete()
{
_ladderClimb = false;
transform.localPosition = _activeLedge.GetStandPos();
_anim.SetBool("LadderClimb", false);
_controller.enabled = true;
this.transform.parent = null;
}
override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
var player = animator.gameObject.transform.parent.GetComponent<Player>();
if (player != null)
{
player.LadderClimbComplete();
}
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store