From cc360b3932f5ce3d87e9cd58c804adafcc7149ad Mon Sep 17 00:00:00 2001 From: Jens Pitkanen Date: Thu, 15 Aug 2019 01:08:07 +0300 Subject: [PATCH] Add pushback to rocket --- Assets/Scripts/Guns/Rocket.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Assets/Scripts/Guns/Rocket.cs b/Assets/Scripts/Guns/Rocket.cs index 9bd31d9..b6e2017 100644 --- a/Assets/Scripts/Guns/Rocket.cs +++ b/Assets/Scripts/Guns/Rocket.cs @@ -59,9 +59,14 @@ namespace Saltosion.OneWeapon.Guns { Collider2D[] NearbyColliders = Physics2D.OverlapCircleAll(transform.position, ExplodeRadius); foreach (Collider2D curr in NearbyColliders) { - Vector2 dir = (curr.transform.position - transform.position); - float ScaledDistance = 1 - Mathf.Clamp((dir.magnitude - (ExplodeRadius / 3)) / (ExplodeRadius - (ExplodeRadius / 3)), 0, 1); - Bullet.DoDamage(ScaledDistance * 20, ScaledDistance * 2, curr, dir.normalized); + Vector2 Delta = (curr.transform.position - transform.position); + Vector2 Dir = Delta.normalized; + float ScaledDistance = 1 - Mathf.Clamp((Delta.magnitude - (ExplodeRadius / 3)) / (ExplodeRadius - (ExplodeRadius / 3)), 0, 1); + Bullet.DoDamage(ScaledDistance * 20, ScaledDistance * 2, curr, Dir); + if (curr.attachedRigidbody != null && curr.attachedRigidbody.bodyType == RigidbodyType2D.Dynamic) { + // FIXME: AcceleratedMovement currently overrides Rigidbody.velocity so this doesn't do anything + curr.attachedRigidbody.AddForce(Dir * 10f, ForceMode2D.Impulse); + } } // Do damage here, kill everyone