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/PlayerController.cs | 34 ++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'code/pawn/component/movement/PlayerController.cs') 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