BITFALL/Assets/Artists/Scripts/Entity/KinematicMovement/EntityKinematicMovementChar...

79 lines
3.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using BITKit;
using BITKit.Entities;
using KinematicCharacterController;
namespace BITFALL.Entites
{
public partial class EntityKinematicMovement : EntityPlayerComponent, ICharacterController
{
public void BeforeCharacterUpdate(float deltaTime)
{
CurrentState?.BeforeCharacterUpdate(deltaTime);
}
public void AfterCharacterUpdate(float deltaTime)
{
CurrentState?.AfterCharacterUpdate(deltaTime);
var velocity = transform.InverseTransformDirection(motor.Velocity);
var baseVelocity = transform.InverseTransformDirection(motor.BaseVelocity) / moveSpeed;
groundState.being = groundState.shouldBe = motor.GroundingStatus.GroundCollider is not null || motor.GroundingStatus.FoundAnyGround;
entity.Set<bool>(_isRunning, runState);
entity.Set<bool>(_isGrounded, groundState);
entity.Set<bool>(_isCrouched, crouchState);
entity.Set<float>(_vertical, baseVelocity.z);
entity.Set<float>(_horizontal, baseVelocity.x);
entity.Set<float>(_sqrMagnitude, velocity.GetLength()/_moveSpeed);
var normalized = velocity.normalized;
if (normalized.sqrMagnitude is not 0)
{
entity.Set<float>(_MoveVertical, normalized.z);
entity.Set<float>(_MoveHorizontal, normalized.x);
}
}
public bool IsColliderValidForCollisions(Collider coll)
{
return ignoreColliders.Contains(coll) is false;
}
public void OnDiscreteCollisionDetected(Collider hitCollider)
{
currentState?.OnDiscreteCollisionDetected(hitCollider);
}
public void OnGroundHit(Collider hitCollider, Vector3 hitNormal, Vector3 hitPoint, ref HitStabilityReport hitStabilityReport)
{
currentState?.OnGroundHit(hitCollider, hitNormal, hitPoint, ref hitStabilityReport);
}
public void OnMovementHit(Collider hitCollider, Vector3 hitNormal, Vector3 hitPoint, ref HitStabilityReport hitStabilityReport)
{
currentState?.OnMovementHit(hitCollider, hitNormal, hitPoint, ref hitStabilityReport);
}
public void PostGroundingUpdate(float deltaTime)
{
currentState?.PostGroundingUpdate(deltaTime);
}
public void ProcessHitStabilityReport(Collider hitCollider, Vector3 hitNormal, Vector3 hitPoint, Vector3 atCharacterPosition, Quaternion atCharacterRotation, ref HitStabilityReport hitStabilityReport)
{
currentState?.ProcessHitStabilityReport(hitCollider, hitNormal, hitPoint, atCharacterPosition, atCharacterRotation, ref hitStabilityReport);
}
public void UpdateRotation(ref Quaternion currentRotation, float deltaTime)
{
CurrentState?.UpdateRotation(ref currentRotation, deltaTime);
}
public void UpdateVelocity(ref Vector3 currentVelocity, float deltaTime)
{
CurrentState?.UpdateVelocity(ref currentVelocity, deltaTime);
}
}
}