Skip to content

Commit

Permalink
fix throw events
Browse files Browse the repository at this point in the history
  • Loading branch information
stilnat committed Dec 7, 2024
1 parent 7d4d9f8 commit bff6d8f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Assets/Scripts/SS3D/Systems/Animations/AimController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace SS3D.Systems.Animations
public class AimController : NetworkActor
{

public event Action<bool, bool> OnAim;
public event Action<bool, bool> OnAim;

[SerializeField]
private Hands _hands;
Expand Down Expand Up @@ -95,7 +95,7 @@ private void SyncAimingToThrow(bool wasAiming, bool isAiming, bool asServer)
private void SyncAimingToShoot(bool wasAiming, bool isAiming, bool asServer)
{
_bodyAimRig.weight = isAiming ? 0.3f : 0f;
OnAim?.Invoke(isAiming, false);
OnAim?.Invoke(this, isAiming);
}

[Client]
Expand Down
18 changes: 10 additions & 8 deletions Assets/Scripts/SS3D/Systems/Animations/HoldController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using FishNet.Object;
using FishNet.Object.Synchronizing;
using FishNet.Serializing;
using JetBrains.Annotations;
using SS3D.Core.Behaviours;
using SS3D.Interactions;
using SS3D.Systems.Entities.Humanoid;
Expand Down Expand Up @@ -166,13 +167,8 @@ public void BringToHand(Hand hand, AbstractHoldable holdable, float duration)
/// <param name="duration"> The time in second to go from the current item position to its updated position</param>
/// <param name="toThrow"> True the item should be in a ready to throw position</param>
public void UpdateItemPositionConstraintAndRotation(
Hand hand, AbstractHoldable item, float duration)
[NotNull] Hand hand, [NotNull] AbstractHoldable item, float duration)
{
if (item == null)
{
return;
}

bool toThrow = _aimController.IsAimingToThrow;
bool withTwoHands = _hands.TryGetOppositeHand(hand, out Hand oppositeHand) && item.CanHoldTwoHand && oppositeHand.Empty;

Expand Down Expand Up @@ -331,10 +327,16 @@ private void HandleIntentChange(object sender, IntentType e)

private void HandleAimChange(bool isAiming, bool toThrow)
{
AbstractHoldable holdable = _hands.SelectedHand.ItemInHand?.Holdable;
if (!_hands.SelectedHand.ItemInHand)
{
return;
}

AbstractHoldable holdable = _hands.SelectedHand.ItemInHand.Holdable;
Gun gun = null;

// handle aiming with shoulder aim
if (holdable.TryGetComponent(out Gun gun) && !toThrow && isAiming)
if (holdable && holdable.TryGetComponent(out gun) && !toThrow && isAiming)
{
gun.transform.parent = _hands.SelectedHand.Hold.ShoulderWeaponPivot;

Expand Down

0 comments on commit bff6d8f

Please sign in to comment.