protected void UpdateAnimation(float deltaTime) { var input = new AnimatedMotorProperties() { MoveSpeedNormalized = _actor.IsPaused ? 0f : _groundVelocity.magnitude / runSpeed, IsGrounded = _isGrounded, DirectionY = Mathf.Clamp01(Mathf.InverseLerp(1f, -1f, Rigidbody.velocity.y)), VelocityX = Vector3.Dot(_groundVelocity, transform.right) / runSpeed, VelocityZ = Vector3.Dot(_groundVelocity, transform.forward) / runSpeed, IsHitReacting = _actor.HitReaction.InProgress }; OnAnimatedPropertiesChanged?.Invoke(input); // Set the center of mass to the point on the collider directly below the center, using it's current rotation. var length = hitBoxCollider.height * 0.5f + groundCheckHeight; var ray = new Ray(transform.TransformPoint(hitBoxCollider.center) + Vector3.down * length, Vector3.up); hitBoxCollider.Raycast(ray, out var hitInfo, length); _groundCheckPoint = hitInfo.point; }
public void AfterCharacterUpdate(float deltaTime) { // Handle jump-related values { // Handle jumping pre-ground grace period if (_jumpRequested && _timeSinceJumpRequested > JumpPreGroundingGraceTime) { _jumpRequested = false; } // Handle jumping while sliding if (AllowJumpingWhenSliding ? Motor.GroundingStatus.FoundAnyGround : Motor.GroundingStatus.IsStableOnGround) { // If we're on a ground surface, reset jumping values if (!_jumpedThisFrame) { _jumpConsumed = false; } _timeSinceLastAbleToJump = 0f; } else { // Keep track of time since we were last able to jump (for grace period) _timeSinceLastAbleToJump += deltaTime; } } var input = new AnimatedMotorProperties() { MoveSpeedNormalized = Motor.BaseVelocity.magnitude / RunSpeed, IsGrounded = Motor.GroundingStatus.FoundAnyGround, DirectionY = Mathf.Clamp01(Mathf.InverseLerp(1f, -1f, Motor.Velocity.y)), VelocityX = Vector3.Dot(Motor.BaseVelocity, Motor.CharacterRight) / RunSpeed, VelocityZ = Vector3.Dot(Motor.BaseVelocity, Motor.CharacterForward) / RunSpeed, IsHitReacting = _isHitReacting }; OnAnimatedPropertiesChanged?.Invoke(input); }