JumpBoots Attempt №2 (#36862)
Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> Co-authored-by: unknown <wainzor1337@gmail.com> Co-authored-by: ScarKy0 <scarky0@onet.eu>
This commit is contained in:
35
Content.Shared/Movement/Systems/SharedJumpAbilitySystem.cs
Normal file
35
Content.Shared/Movement/Systems/SharedJumpAbilitySystem.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Content.Shared.Gravity;
|
||||
using Content.Shared.Movement.Components;
|
||||
using Content.Shared.Throwing;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
|
||||
namespace Content.Shared.Movement.Systems;
|
||||
|
||||
public sealed partial class SharedJumpAbilitySystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly ThrowingSystem _throwing = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly SharedGravitySystem _gravity = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<JumpAbilityComponent, GravityJumpEvent>(OnGravityJump);
|
||||
}
|
||||
|
||||
private void OnGravityJump(Entity<JumpAbilityComponent> entity, ref GravityJumpEvent args)
|
||||
{
|
||||
if (_gravity.IsWeightless(args.Performer))
|
||||
return;
|
||||
|
||||
var xform = Transform(args.Performer);
|
||||
var throwing = xform.LocalRotation.ToWorldVec() * entity.Comp.JumpDistance;
|
||||
var direction = xform.Coordinates.Offset(throwing); // to make the character jump in the direction he's looking
|
||||
|
||||
_throwing.TryThrow(args.Performer, direction, entity.Comp.JumpThrowSpeed);
|
||||
|
||||
_audio.PlayPredicted(entity.Comp.JumpSound, args.Performer, args.Performer);
|
||||
args.Handled = true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user