added jumps
This commit is contained in:
1 parent
43ddb1b3b5
commit
ec8d233189
4 files changed
+61
-4
No files matched your search
@@ -33,6 +33,7 @@ namespace Code.Gameplay.Character.Core
|
||||
inputs.MoveAxisForward = moveInput.y;
|
||||
inputs.MoveAxisRight = moveInput.x;
|
||||
inputs.SprintPressed = _inputService.SprintHeld;
|
||||
inputs.JumpPressed = _inputService.JumpPressed;
|
||||
|
||||
inputs.CameraRotation = FindFirstObjectByType<CameraController>().GetCameraRotation();
|
||||
inputs.CameraPlanarDirection = FindFirstObjectByType<CameraController>().GetPlanarDirection();
|
||||
|
||||
@@ -17,8 +17,14 @@ namespace Code.Gameplay.Character.Controller
|
||||
[SerializeField] private float maxStableMoveSpeed;
|
||||
[SerializeField] private float sprintMoveSpeed;
|
||||
[SerializeField] private float stableMovementSharpness;
|
||||
[SerializeField] private float jumpSpeed;
|
||||
[SerializeField] private float jumpCooldownDuration;
|
||||
[SerializeField] private Vector3 gravity;
|
||||
|
||||
private float _jumpCooldownTimer;
|
||||
private float JumpCooldownDuration => jumpCooldownDuration;
|
||||
public bool CanJump => _jumpCooldownTimer <= 0f;
|
||||
|
||||
public void SetPosition(Vector3 position) => motor.SetPosition(position);
|
||||
public void SetRotation(Quaternion rotation) => motor.SetRotation(rotation);
|
||||
|
||||
@@ -31,7 +37,8 @@ namespace Code.Gameplay.Character.Controller
|
||||
_groundMovement = new GroundMovementSystem(
|
||||
maxStableMoveSpeed,
|
||||
sprintMoveSpeed,
|
||||
stableMovementSharpness
|
||||
stableMovementSharpness,
|
||||
jumpSpeed
|
||||
);
|
||||
_airMovement = new AirMovementSystem(
|
||||
gravity
|
||||
@@ -44,6 +51,17 @@ namespace Code.Gameplay.Character.Controller
|
||||
public void SetInputs(ref CharacterInputs inputs)
|
||||
{
|
||||
_inputHandler.ProcessInputs(ref inputs, motor);
|
||||
|
||||
var jumpInput = inputs.JumpPressed;
|
||||
|
||||
if (jumpInput && CanJump)
|
||||
{
|
||||
_groundMovement.RequestJump(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
_groundMovement.RequestJump(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateRotation(ref Quaternion currentRotation, float deltaTime)
|
||||
@@ -58,17 +76,27 @@ namespace Code.Gameplay.Character.Controller
|
||||
if (wasGrounded)
|
||||
{
|
||||
_groundMovement?.UpdateVelocity(ref currentVelocity, _inputHandler, motor, deltaTime);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
_airMovement?.UpdateVelocity(ref currentVelocity, deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
public void TriggerJump()
|
||||
{
|
||||
_jumpCooldownTimer = JumpCooldownDuration;
|
||||
}
|
||||
|
||||
public void BeforeCharacterUpdate(float deltaTime) { }
|
||||
public void PostGroundingUpdate(float deltaTime) { }
|
||||
public void AfterCharacterUpdate(float deltaTime) { }
|
||||
|
||||
public void AfterCharacterUpdate(float deltaTime)
|
||||
{
|
||||
_jumpCooldownTimer -= deltaTime;
|
||||
if (_jumpCooldownTimer < 0f) _jumpCooldownTimer = 0f;
|
||||
}
|
||||
|
||||
public bool IsColliderValidForCollisions(Collider coll) => true;
|
||||
public void OnGroundHit(Collider hitCollider, Vector3 hitNormal, Vector3 hitPoint, ref HitStabilityReport hitStabilityReport) { }
|
||||
public void OnMovementHit(Collider hitCollider, Vector3 hitNormal, Vector3 hitPoint, ref HitStabilityReport hitStabilityReport) { }
|
||||
|
||||
Reference in new issue
Block a user