Player/LongJump.cs
public sealed class LongJump : Item, IPlayerEvent
{
[Property] float HorizontalForce { get; set; } = 1000;
[Property] float VerticalForce { get; set; } = 350;
[Property] SoundEvent JumpSound { get; set; }
TimeSince timeSinceDucked { get; set; }
public override void OnAdded( Player player )
{
// Enable me
GameObject.Enabled = true;
GameObject.Network.Refresh();
}
protected override void OnFixedUpdate()
{
if ( !Owner.IsLocalPlayer ) return;
if ( !Owner.Controller.IsOnGround ) return;
if ( Owner.Controller.Velocity.Length > 0 && Input.Pressed( "duck" ) )
{
timeSinceDucked = 0;
}
}
void IPlayerEvent.OnJump()
{
if ( timeSinceDucked < 0.5f )
{
var rot = Owner.EyeTransform.Rotation;
rot = rot.Angles().WithPitch( 0f );
Owner.Controller.Jump( rot.Forward * HorizontalForce + Vector3.Up * VerticalForce );
if ( JumpSound.IsValid() )
{
GameObject.PlaySound( JumpSound );
}
}
}
}