public override void ComponentUpdate() { if (actor.IsAlive()) { UpdateState(); } else { // Hack to disable collider without disabling gravity if (collider2d is BoxCollider2D boxCollider) { boxCollider.size = new Vector2(0.01f, 0.01f); boxCollider.offset = new Vector2(0, -(relativeNpcHeightInUnits / 4)); } else if (collider2d is PolygonCollider2D polygonCollider) { polygonCollider.points = new Vector2[] { Vector2.zero }; } else if (collider2d is CapsuleCollider2D capsuleCollider) { capsuleCollider.size = new Vector2(0.01f, 0.01f); capsuleCollider.offset = new Vector2(0f, -(relativeNpcHeightInUnits / 4)); } despawner.BeginDespawn(); onActiveStateBehavior.enabled = false; onIdleStateBehavior.enabled = false; } base.ComponentUpdate(); }
private void UpdateState() { if (playerActor.IsAlive()) { var fuckAss = movementBounds.SurroundsPoint(player.transform.position); if (!useMovementBoundaries || movementBounds.SurroundsPoint(player.transform.position)) { DoActiveBehavior(); } else { DoIdleBehavior(); } } else { DoIdleBehavior(); } }
public override void ComponentUpdate() { if (actor.IsAlive() && !isTiedUp && !isMovementLocked) { // If we are currently touching any ladder components, we are climbing. isClimbing = CollidingTriggers.Any(tr => UnityUtils.Exists(tr) && tr.GetComponent <LadderComponent>() != null); if (!isClimbing) { IsGravityEnabled = true; if (IsGrounded) { if (Input.IsKeyPressed(InputConstants.K_JUMP)) { animator.Jump(); // Apply force to the rigid body directly so that gravity pulls us down AddRigidBodyForce(0, jumpHeight); } } if (Input.IsKeyPressed(InputConstants.K_SWING_SWORD) && actor.TryDepleteStamina(dodgeStaminaRequired / 2)) { // Shake the camera cameraEffector.SwingRight(); // If we are in the air and the player is holding "up", do a GRAND SLAM if (Input.IsKeyHeld(InputConstants.K_MOVE_UP) && !IsGrounded && !IsAttacking) { animator.GroundPound(); } // if we are in the air and player holds "down", do an uppercut, but only once before the player lands else if (Input.IsKeyHeld(InputConstants.K_MOVE_DOWN) && !IsAttacking && !usedUppercut) { AddRigidBodyForce(0, upperCutHeight); animator.Uppercut(); // Signals that we've already used the uppercut during this jump. // This will be reset to false upon landing. usedUppercut = true; } else { animator.Attack(); } } } else { // disable gravity if we're on a ladder IsGravityEnabled = false; } if (Input.IsKeyPressed(InputConstants.K_DODGE_LEFT) && actor.TryDepleteStamina(dodgeStaminaRequired)) { AddImpact(-dodgeSpeed, 0); } if (Input.IsKeyPressed(InputConstants.K_DODGE_RIGHT) && actor.TryDepleteStamina(dodgeStaminaRequired)) { AddImpact(dodgeSpeed, 0); } // Translate user controls into the player's movements UpdateFootVelocity(); } else if (!actor.IsAlive()) { if (!isDeadAndHitGround) { // Force Player to keep falling FootVelocity = new Vector2(0, CurrentVelocity.y); if (IsGrounded) { isDeadAndHitGround = true; } } else { // Player is dead, and fell to the ground. // Disable all the physics stuff, so the dead body just stays where it was on screen. if (collider2d is CapsuleCollider2D capsuleCollider) { capsuleCollider.size = new Vector2(0.01f, 0.01f); capsuleCollider.offset = new Vector2(0f, -1f); } FootVelocity = Vector2.zero; } } UpdateAnimator(); // tell the melee collider to face left if the player is facing left -_- meleeCollider.IsFlipped = animator.SkeletonIsFlipped; base.ComponentUpdate(); }