From d599275439cd35e0d3e3146e39be809df55459bd Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Sat, 29 Jul 2023 15:27:57 +0100 Subject: Add footsteps --- code/pawn/component/movement/BaseController.cs | 9 +++++-- code/pawn/component/movement/PlayerController.cs | 34 ++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 4 deletions(-) (limited to 'code/pawn/component') diff --git a/code/pawn/component/movement/BaseController.cs b/code/pawn/component/movement/BaseController.cs index 0b92c75..02c0be1 100644 --- a/code/pawn/component/movement/BaseController.cs +++ b/code/pawn/component/movement/BaseController.cs @@ -3,7 +3,12 @@ namespace MurderGame; //TODO make spectatro a controller -public class BaseController : EntityComponent +public abstract class BaseController { - public Player Player { get; set; } + public virtual float SpeedMultiplier { get; set; } = 1; + + public abstract void Simulate(Player player); + + public abstract bool HasEvent(string eventName); + } diff --git a/code/pawn/component/movement/PlayerController.cs b/code/pawn/component/movement/PlayerController.cs index 2c9a9b9..f2658af 100644 --- a/code/pawn/component/movement/PlayerController.cs +++ b/code/pawn/component/movement/PlayerController.cs @@ -18,6 +18,9 @@ public class PlayerController : EntityComponent Vector3 LadderNormal; + TimeSince TimeSinceFootstep; + bool FootstepFoot; + bool Grounded => Entity.GroundEntity.IsValid(); public void Simulate( Player player ) @@ -43,13 +46,40 @@ public class PlayerController : EntityComponent if (zVel < -500) { var damageInfo = DamageInfo.Generic( Math.Abs((float)(zVel * 0.05)) ); - Entity.TakeDamage( damageInfo ); Entity.PlaySound( "fall" ); + var trace = Trace.Ray( Entity.Position, Entity.Position + Vector3.Down * 20f ) + .Radius( 1f ) + .Ignore( Entity ) + .Run(); + if (trace.Hit) + { + trace.Surface.DoFootstep( Entity, trace, FootstepFoot ? 1 : 0, 70f ); + } + Entity.TakeDamage( damageInfo ); return; } } - var sprintMultiplier = TeamOperations.CanSprint( team ) ? (Input.Down( "run" ) ? 2.5f : 1f) : 1f; + var isSprinting = TeamOperations.CanSprint( team ) && Input.Down( "run" ); + var footstepTimeThreshold = isSprinting ? 0.2 : 0.3; + + if (moveVector.Length > 0 && TimeSinceFootstep > footstepTimeThreshold) + { + var trace = Trace.Ray( Entity.Position, Entity.Position + Vector3.Down * 20f ) + .Radius( 1f ) + .Ignore( Entity ) + .Run(); + + if (trace.Hit) + { + FootstepFoot = !FootstepFoot; + + trace.Surface.DoFootstep( Entity, trace, FootstepFoot ? 1 : 0, 40f ); + + TimeSinceFootstep = 0; + } + } + var sprintMultiplier = (isSprinting ? 2.5f : 1f); Entity.Velocity = Accelerate( Entity.Velocity, moveVector.Normal, moveVector.Length, SpeedMultiplier * 200.0f * sprintMultiplier, 7.5f ); Entity.Velocity = ApplyFriction( Entity.Velocity, 4.0f ); -- cgit v1.2.3-70-g09d2