diff options
| author | Leonardo Bishop <me@leonardobishop.com> | 2023-07-29 15:27:57 +0100 |
|---|---|---|
| committer | Leonardo Bishop <me@leonardobishop.com> | 2023-07-29 15:27:57 +0100 |
| commit | d599275439cd35e0d3e3146e39be809df55459bd (patch) | |
| tree | cd64510328d528cab600a071d30ab3ec9461b17d /code/pawn/component/movement/PlayerController.cs | |
| parent | 95b2259eb4d7362b137d26037f8312b3d80f0244 (diff) | |
Add footsteps
Diffstat (limited to 'code/pawn/component/movement/PlayerController.cs')
| -rw-r--r-- | code/pawn/component/movement/PlayerController.cs | 34 |
1 files changed, 32 insertions, 2 deletions
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<Player> Vector3 LadderNormal;
+ TimeSince TimeSinceFootstep;
+ bool FootstepFoot;
+
bool Grounded => Entity.GroundEntity.IsValid();
public void Simulate( Player player )
@@ -43,13 +46,40 @@ public class PlayerController : EntityComponent<Player> 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 );
|
