public override void PerformAction(float delta) {
// guard: something goes wrong!
if (character.ladder == null) {
character.ExitState(States.Ladder);
return;
}
Ladder ladder = character.ladder;
Vector2 in2d = input.GetAxisRaw();
if (character.IsOnArea(Areas.Ladder) && character.IsOnState(States.Ladder)) {
// disable x movement
character.velocity.x = 0;
character.velocity.y = speed * in2d.y;
}
// TODO transition
if (centering) {
float ladderCenter = ladder.GetComponent<BoxCollider2D>().bounds.center.x;
float characterX = character.GetCenter().x;
if (Math.Abs(characterX - ladderCenter) < 0.05) {
centering = false;
character.velocity.x = 0;
} else {
// instant move to the center of the ladder!
Mathf.SmoothDamp(characterX, ladderCenter, ref character.velocity.x, towardsTime, towardsSpeed, delta);
}
}
if (ladder.topDismount && ladder.IsAtTop(character, character.feet) && in2d.y > 0) {
// top dismount enabled and reached
character.velocity = Vector2.zero;
ladder.Dismount(character);
} else if (ladder.bottomDismount && ladder.IsAtBottom(character, character.feet) && in2d.y < 0) {
// bottom dismount enabled and reached
character.velocity = Vector2.zero;
ladder.Dismount(character);
} else if (!ladder.topDismount && ladder.IsAboveTop(character, character.head) && in2d.y > 0) {
// can't dismount (vine) don't let the head 'overflow' the ladder
character.velocity = Vector2.zero;
} else if (!ladder.bottomDismount && ladder.IsAtBottom(character, character.feet) && in2d.y < 0) {
// can't dismount (vine) don't let the head 'overflow' the ladder
// caveat: Vine cannot be near ground
character.velocity = Vector2.zero;
}
character.SetFacing(in2d.x);
// check for dismount conditions
if (in2d.x != 0) {
// do not allow to jump without telling the direction.
// move up if you want it
if (dismountJumping && input.IsActionHeld(actionJump.action)) {
dismount.Reset();
character.ladder.Dismount(character);
character.ladder = null;
actionJump.Jump(new JumpConstant(character,
jumpOff.Clone((int) character.faceDir)
));
} else if (dismount.Ready()) {
character.velocity = Vector2.zero;
character.ladder.Dismount(character);
character.ladder = null;
}
} else {
dismount.Reset();
}
}