Skip to content

Commit

Permalink
Sync with simple-weapon-base
Browse files Browse the repository at this point in the history
  • Loading branch information
timmybo5 committed Sep 13, 2023
1 parent a37ec38 commit aed0169
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 21 deletions.
7 changes: 7 additions & 0 deletions code/swb_base/ViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ private void HandleWalkAnimation()
else if (localVel.x < 0.0f)
yaw = 3.0f * (localVel.x / maxWalkSpeed);

// Check if ADS & firing
if (weapon.IsZooming && weapon.TimeSincePrimaryAttack < 0.1f)
{
targetVectorRot -= new Vector3(0, 0, roll);
return;
}

// Perform walk cycle
targetVectorPos -= new Vector3((-MathF.Cos(breatheTime / 2.0f) / 5.0f) * walkSpeed / maxWalkSpeed - yaw / 4.0f, 0.0f, 0.0f);
targetVectorRot -= new Vector3((Math.Clamp(MathF.Cos(breatheTime), -0.3f, 0.3f) * 2.0f) * walkSpeed / maxWalkSpeed, (-MathF.Cos(breatheTime / 2.0f) * 1.2f) * walkSpeed / maxWalkSpeed - yaw * 1.5f, roll);
Expand Down
1 change: 1 addition & 0 deletions code/swb_base/WeaponBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public override void ActiveEnd(Entity ent, bool dropped)
{
// Attachments
HandleAttachments(false);
wasZooming = false;

base.ActiveEnd(ent, dropped);
}
Expand Down
6 changes: 6 additions & 0 deletions code/swb_base/attachments/BodyGroupSight.HunterScope2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ public class HunterScope2D : BodyGroupSight
"100% accurate while scoped in"
};

public override void OnUnequip(WeaponBase weapon)
{
base.OnUnequip(weapon);
OnZoomEnd(weapon);
}

public override void OnZoomStart(WeaponBase weapon)
{
WeaponBaseSniper.OnScopeStart(weapon, ZoomInSound, ZoomInDelay);
Expand Down
4 changes: 4 additions & 0 deletions code/swb_base/ui/SniperScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public override void Tick()
// Show when zooming
Style.Opacity = !weapon.IsScoped ? 0 : 1;

// Check if ADS & firing
if (weapon.IsZooming && weapon.TimeSincePrimaryAttack < 0.1f)
return;

// Movement impact
var velocityJump = player.Velocity.z * 0.02f;
var velocityMove = (Math.Abs(player.Velocity.y) + Math.Abs(player.Velocity.x)) * 0.005f;
Expand Down
34 changes: 13 additions & 21 deletions code/swb_player/PlayerBase.Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,19 +211,6 @@ public override void BuildInput()
if (Input.StopProcessing)
return;

var look = Input.AnalogLook;

if (ViewAngles.pitch > 90f || ViewAngles.pitch < -90f)
{
look = look.WithYaw(look.yaw * -1f);
}

var viewAngles = ViewAngles;
viewAngles += look;
viewAngles.pitch = viewAngles.pitch.Clamp(-89f, 89f);
viewAngles.roll = 0f;
ViewAngles = viewAngles.Normal;

// Adjust mouse sensitivity based on weapon suggestion
if (ActiveChild is WeaponBase weapon)
{
Expand All @@ -232,25 +219,30 @@ public override void BuildInput()
{
if (weapon.IsScoped && weapon.General.ScopedAimSensitivity > 0)
{
ViewAngles = Angles.Lerp(OriginalViewAngles, ViewAngles, weapon.General.ScopedAimSensitivity);
Input.AnalogLook *= weapon.General.ScopedAimSensitivity;
}
else if (weapon.IsZooming && weapon.General.AimSensitivity > 0)
{
ViewAngles = Angles.Lerp(OriginalViewAngles, ViewAngles, weapon.General.AimSensitivity);
Input.AnalogLook *= weapon.General.AimSensitivity;
}
}
}

var look = Input.AnalogLook;

if (ViewAngles.pitch > 90f || ViewAngles.pitch < -90f)
look = look.WithYaw(look.yaw * -1f);

var viewAngles = ViewAngles;
viewAngles += look;
viewAngles.pitch = viewAngles.pitch.Clamp(-89f, 89f);
viewAngles.roll = 0f;
ViewAngles = viewAngles.Normal;

ActiveChild?.BuildInput();
DoWeaponRecoil();

GetActiveController()?.BuildInput();

HandleFlinch();

if (Input.StopProcessing)
return;

GetActiveAnimator()?.BuildInput();
}

Expand Down

0 comments on commit aed0169

Please sign in to comment.