Add pushback to rocket

This commit is contained in:
Jens Pitkänen 2019-08-15 01:08:07 +03:00
parent a2340cbd25
commit cc360b3932

View File

@ -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