Damage System Rewrite

New damage system, much easier to understand
Splash damage support
Hardpoint armor consolidated with hull armor
Minimap shows view cone
New industry standard palette for temperature display
Temperature range display contains palette
Restoring loadouts now ignores temperature and armor
Items can ignore thermal mass when adding heat
Burst weapons can consume single ammo (mainly shotguns)
New missile type that follows crosshairs
New airburst projectile type that deals splash damage
Auto Shotgun and Charged Shotgun
This commit is contained in:
Reinier Vens 2021-02-01 08:13:14 +00:00
commit 3a9ee2ccf7
55 changed files with 14253 additions and 2206 deletions

View file

@ -1,8 +1,8 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.Mathematics;
using UnityEngine;
using Unity.Mathematics;
using static Unity.Mathematics.math;
using static Unity.Mathematics.noise;
using Random = UnityEngine.Random;
@ -12,6 +12,12 @@ public class GuidedProjectile : MonoBehaviour
{
public Prototype HitEffect;
public Prototype ChildProjectile;
public Prototype AirburstProjectile;
public int AirburstCount;
public float AirburstDirectionality;
public float AirburstDistance;
public float AirburstRange;
public float AirburstVelocity;
public int Children;
public float SplitTime;
public float SplitSeparationForwardness;
@ -26,13 +32,13 @@ public class GuidedProjectile : MonoBehaviour
public float TopSpeed;
public Transform Source;
public Transform Target;
public Func<Vector3> TargetPosition;
private float _phase;
private float _prevDist;
private bool _active;
private bool _alive;
private List<GuidedProjectile> _children = new List<GuidedProjectile>();
public float3 StartPosition { get; set; }
public float Range { get; set; }
public Vector3 Velocity { get; set; }
@ -63,18 +69,20 @@ public class GuidedProjectile : MonoBehaviour
if (_active)
{
if (!Target)
if (TargetPosition == null && !Target)
{
StartCoroutine(FadeOut());
return;
}
var diff = Target.position - transform.position;
var targetPosition = TargetPosition?.Invoke() ?? Target.position;
var diff = targetPosition - transform.position;
var targetDist = diff.magnitude;
var position = (float3) t.position;
var sourceDist = length(StartPosition.xz - position.xz);
if (sourceDist > Range || _prevDist < targetDist)
if (sourceDist > Range || dot(diff,Velocity) < 0 || AirburstCount > 0 && targetDist < AirburstDistance)
{
StartCoroutine(FadeOut());
if (HitEffect != null)
@ -82,6 +90,27 @@ public class GuidedProjectile : MonoBehaviour
var ht = HitEffect.Instantiate<Transform>();
ht.position = t.position;
}
if (AirburstCount > 0 && AirburstProjectile)
{
var targetDiff = Target.position - transform.position;
if (targetDiff.magnitude < AirburstRange)
{
for (int i = 0; i < AirburstCount; i++)
{
var child = AirburstProjectile.Instantiate<Projectile>();
child.StartPosition = child.transform.position = t.position;
var randomDirection = Random.onUnitSphere;
child.Velocity = Vector3.Lerp(randomDirection, targetDiff.normalized, AirburstDirectionality).normalized * AirburstVelocity;
child.Range = AirburstRange;
child.Damage = Damage / AirburstCount;
child.Penetration = Penetration;
child.Spread = Spread;
child.DamageType = DamageType;
child.SourceEntity = SourceEntity;
}
}
}
return;
}
_prevDist = targetDist;
@ -99,7 +128,6 @@ public class GuidedProjectile : MonoBehaviour
var child = ChildProjectile.Instantiate<GuidedProjectile>();
child.transform.position = t.position;
child.StartPosition = StartPosition;
_children.Add(child);
var randomDirection = normalize(Random.insideUnitCircle);
var perpendicularRandom = randomDirection.x * right + randomDirection.y * up;
child.Velocity = normalize(lerp(perpendicularRandom, dir, SplitSeparationForwardness)) * length(Velocity) * SplitSeparationVelocity;
@ -108,14 +136,14 @@ public class GuidedProjectile : MonoBehaviour
child.Penetration = Penetration;
child.Spread = Spread;
child.DamageType = DamageType;
child.Source = Source;
child.Target = Target;
child.SourceEntity = SourceEntity;
child.GuidanceCurve = GuidanceCurve;
child.LiftCurve = LiftCurve;
child.ThrustCurve = ThrustCurve;
child.Thrust = Thrust;
child.TopSpeed = TopSpeed;
child.Source = Source;
child.Target = Target;
child.SourceEntity = SourceEntity;
child.Frequency = Frequency;
child.Thrust = Thrust;
}
@ -189,14 +217,8 @@ public class GuidedProjectile : MonoBehaviour
Particles.Stop(true, ParticleSystemStopBehavior.StopEmitting);
var startTime = Time.time;
var lifetime = Particles.main.startLifetime.constant;
while (Time.time - startTime < lifetime || _children.Count > 0)
while (Time.time - startTime < lifetime)
{
for (var index = 0; index < _children.Count; index++)
{
if (!_children[index].gameObject.activeSelf)
_children.RemoveAt(index--);
}
yield return null;
}
GetComponent<Prototype>().ReturnToPool();

View file

@ -1,6 +1,8 @@
using System.Collections;
using System.Collections.Generic;
using Unity.Mathematics;
using UnityEngine;
using static Unity.Mathematics.math;
public class GuidedProjectileManager : InstantWeaponEffectManager
{
@ -30,6 +32,29 @@ public class GuidedProjectileManager : InstantWeaponEffectManager
p.Thrust = source.Entity.ItemManager.Evaluate(launcher.Thrust, item.EquippableItem, source.Entity);
p.TopSpeed = source.Entity.ItemManager.Evaluate(launcher.MissileVelocity, item.EquippableItem, source.Entity);
}
else if(weapon.Data is GuidedWeaponData guidance)
{
var p = ProjectilePrototype.Instantiate<GuidedProjectile>();
p.Source = source.Transform;
p.SourceEntity = source.Entity;
p.Target = target?.Transform;
p.Frequency = guidance.DodgeFrequency;
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
var barrel = source.GetBarrel(hp);
p.StartPosition = p.transform.position = barrel.position;
p.Damage = weapon.Damage;
p.Range = weapon.Range;
p.Penetration = weapon.Penetration;
p.Spread = weapon.DamageSpread;
p.DamageType = weapon.WeaponData.DamageType;
p.GuidanceCurve = guidance.GuidanceCurve.ToCurve();
p.LiftCurve = guidance.LiftCurve.ToCurve();
p.ThrustCurve = guidance.ThrustCurve.ToCurve();
p.Velocity = barrel.forward * weapon.Velocity;
p.Thrust = source.Entity.ItemManager.Evaluate(guidance.Thrust, item.EquippableItem, source.Entity);
p.TopSpeed = source.Entity.ItemManager.Evaluate(guidance.MissileVelocity, item.EquippableItem, source.Entity);
p.TargetPosition = () => source.Entity.Position + length( (float3)source.LookAtPoint.position - source.Entity.Position) * source.Entity.LookDirection;
}
else Debug.LogError($"Weapon {item.EquippableItem.Name} linked to {name} effect, but is not a Launcher!");
}
}

View file

@ -4,13 +4,20 @@ using System.Collections.Generic;
using Unity.Mathematics;
using static Unity.Mathematics.math;
using UnityEngine;
using Random = UnityEngine.Random;
public class Projectile : MonoBehaviour
{
public TrailRenderer Trail;
public float Gravity;
public float Drag = .1f;
public Prototype HitEffect;
public float AirburstDistance;
public float AirburstRange;
public float AirburstVelocity;
public float DirectHitDamageMultiplier = 1;
private bool _alive;
public Zone Zone { get; set; }
@ -45,6 +52,7 @@ public class Projectile : MonoBehaviour
var t = transform;
var position = t.position;
Velocity += Vector3.up * (Gravity * Time.deltaTime);
Velocity *= max(0, 1 - Drag * Time.deltaTime);
var forward = Velocity.normalized;
t.forward = forward;
var ray = new Ray(position, Velocity);
@ -55,7 +63,7 @@ public class Projectile : MonoBehaviour
{
if (hull.Entity != SourceEntity)
{
hull.SendHit(Damage, Penetration, Spread, DamageType, SourceEntity, hit, forward);
hull.SendHit(Damage*DirectHitDamageMultiplier, Penetration, Spread, DamageType, SourceEntity, hit, forward);
transform.position = hit.point;
StartCoroutine(Kill());
}
@ -76,8 +84,23 @@ public class Projectile : MonoBehaviour
}
transform.position += Velocity * Time.deltaTime;
if((transform.position - StartPosition).magnitude > Range)
var distanceTraveled = (transform.position - StartPosition).magnitude;
if(distanceTraveled > Range)
StartCoroutine(Kill());
if (AirburstDistance > 1 && distanceTraveled > AirburstDistance)
{
StartCoroutine(Kill());
var ht = HitEffect.Instantiate<Transform>();
ht.position = t.position;
foreach (var collider in Physics.OverlapSphere(t.position, AirburstRange, 1))
{
var hull = collider.GetComponent<HullCollider>();
if (hull)
{
hull.SendSplash(Damage, DamageType, SourceEntity, (collider.transform.position - t.position).normalized);
}
}
}
}
}

View file

@ -1,6 +1,9 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Mathematics;
using static Unity.Mathematics.math;
using Random = UnityEngine.Random;
public class ProjectileManager : InstantWeaponEffectManager
{
@ -27,6 +30,7 @@ public class ProjectileManager : InstantWeaponEffectManager
p.Spread = weapon.DamageSpread;
p.DamageType = weapon.WeaponData.DamageType;
p.Zone = source.Entity.Zone;
p.AirburstDistance = target != null ? length(source.Entity.Position - target.Entity.Position) : (weapon.Range * .75f);
p.Trail.Clear();
}
}