private void DoPatrol() { Vector3 velocity = new Vector3(groundSpeed, 0f, 0f) * Time.deltaTime; characterController.Move(velocity); if (groundBloodChecker.IsGroundBloodActive().Both()) { this.state = State.SLIPPING; GameObject.Destroy(this._collider); return; } // check if walking into wall. if (groundSpeed > 0 && characterController.collisionState.right || groundSpeed < 0 && characterController.collisionState.left) { TurnAround(); return; } // check if walked off cliff. GroundChecker.CollisionInfo collisionInfo = groundChecker.GetCollisionInfo(); if (groundSpeed < 0 && !collisionInfo.left) { TurnAround(); } else if (groundSpeed > 0 && !collisionInfo.right) { TurnAround(); } }
public override void Tick() { if (slime.inputLocked) { return; } GroundBloodChecker.ActiveBloodInfo activeBloodInfo = slime.groundBloodChecker.IsGroundBloodActive(); GroundChecker.CollisionInfo solidGroundCollisionInfo = slime.groundChecker.GetCollisionInfo(); bool isOnSolidGround = solidGroundCollisionInfo.left || solidGroundCollisionInfo.right; if (isLanding && !didShrink) { if (isOnSolidGround && !activeBloodInfo.Either()) { slime.Shrink(); this.didShrink = true; } } CheckForGroundBlood(); didRunThisFrame = false; if (slime.playerInput.GetDidPressJumpBuffered()) { slime.velocity.y = jumpPower; slime.fsm.ChangeState(slime.stateAirborne, slime.stateAirborne, false); SpawnJumpEffect(); return; } float horizInput = slime.playerInput.GetHorizInput(); if (horizInput != 0f) { float speed = activeBloodInfo.Both() ? slime.horizSpeed * bloodSpeedMultiplier : slime.horizSpeed; float targetVelocityX = horizInput * speed; slime.velocity.x = Mathf.SmoothDamp( slime.velocity.x, targetVelocityX, ref slime.velocityXSmoothing, slime.velocityXSmoothFactorGrounded); if (targetVelocityX != 0f) { didRunThisFrame = true; } } else { slime.velocity.x = 0f; } slime.velocity.y = slime.gravity * Time.deltaTime; if (horizInput != 0f) { slime.FaceMovementDirection(); AudioClip movementSoundEffect = null; if (activeBloodInfo.Both()) { SpawnTrail(horizInput > 0); if (curMovementSoundEffectCooldown >= wetMovementSoundEffectCooldown) { movementSoundEffect = wetGroundMovementAudioClip; } } else if (isOnSolidGround) { if (curMovementSoundEffectCooldown >= solidMovementSoundEffectCooldown) { movementSoundEffect = solidGroundMovementAudioClip; } } if (movementSoundEffect != null) { movementSoundsAudioSource.PlayOneShot(movementSoundEffect); curMovementSoundEffectCooldown = 0f; } } slime.controller.Move(slime.velocity * Time.deltaTime); if (!slime.controller.isGrounded) { slime.fsm.ChangeState(slime.stateAirborne, slime.stateAirborne, true); } if (isLanding) { audioSource.PlayOneShot(landAudioClip); } isLanding = false; curMovementSoundEffectCooldown += Time.deltaTime; }