Skip to content

Commit

Permalink
Fix knockback scaling with the amount of bullets from gun
Browse files Browse the repository at this point in the history
  • Loading branch information
Fueredoriku committed Jun 7, 2024
1 parent efef8b6 commit 571c660
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
12 changes: 12 additions & 0 deletions Assets/Scripts/Augment/BulletModifiers/KnockbackOnShotModifier.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using UnityEngine;

public class KnockbackOnShotModifier : MonoBehaviour, ProjectileModifier
Expand All @@ -12,6 +13,8 @@ public class KnockbackOnShotModifier : MonoBehaviour, ProjectileModifier

private float calculatedPushPower;

private (ProjectileState, List<HitboxController>) collidersHitWithShot;

private void Awake()
{
gunController = transform.parent.GetComponent<GunController>();
Expand All @@ -33,7 +36,16 @@ public void Detach(ProjectileController projectile)
private void KnockAwayTargets(HitboxController controller, ref ProjectileState state)
{
Vector3 normal = gunController.transform.forward;
if (collidersHitWithShot.Item1 == state && collidersHitWithShot.Item2.Contains(controller))
return;

if (collidersHitWithShot.Item1 != state)
{
collidersHitWithShot.Item2.Clear();
collidersHitWithShot.Item1 = state;
}

collidersHitWithShot.Item2.Add(controller);
if (controller.health.TryGetComponent<Rigidbody>(out var rigidbody))
{
// If AI, enable physics for a small time frame
Expand Down
5 changes: 3 additions & 2 deletions Assets/Scripts/Gamestate/PlayerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ private void OnDeath(HealthController healthController, float damage, DamageInfo
{
killer = lastPlayerThatHitMe;
}
if (isAlive)
onDeath?.Invoke(killer, this, info);
if (!isAlive)
return;
onDeath?.Invoke(killer, this, info);
isAlive = false;
aimAssistCollider.SetActive(false);
TurnIntoRagdoll(info);
Expand Down
5 changes: 5 additions & 0 deletions Assets/Scripts/Interactables/ExplodingBarrel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class ExplodingBarrel : MonoBehaviour

private HealthController healthController;

private bool isAlive = true;

private void Start()
{
healthController = GetComponent<HealthController>();
Expand All @@ -30,11 +32,14 @@ private void OnDestroy()

private void Explode(HealthController controller, float damage, DamageInfo info)
{
if (!isAlive)
return;
barrelMesh.enabled = false;
GetComponentsInChildren<Collider>().ToList().ForEach(c => c.enabled = false);
explosion.Explode(info.sourcePlayer);
LeaveMark();
Destroy(gameObject, 4);
isAlive = false;
}

private void LeaveMark()
Expand Down

0 comments on commit 571c660

Please sign in to comment.