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
116 lines
3.7 KiB
C#
116 lines
3.7 KiB
C#
using System;
|
|
using System.Collections;
|
|
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; }
|
|
|
|
public Vector3 StartPosition { get; set; }
|
|
public Vector3 Velocity { get; set; }
|
|
public float Damage { get; set; }
|
|
public float Penetration { get; set; }
|
|
public float Spread { get; set; }
|
|
public DamageType DamageType { get; set; }
|
|
public Entity SourceEntity { get; set; }
|
|
public float Range { get; set; }
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
_alive = true;
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (SourceEntity == null) return;
|
|
|
|
if(_alive)
|
|
{
|
|
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);
|
|
if (Physics.Raycast(ray, out var hit, Velocity.magnitude * Time.deltaTime, 1))
|
|
{
|
|
var hull = hit.collider.GetComponent<HullCollider>();
|
|
if (hull)
|
|
{
|
|
if (hull.Entity != SourceEntity)
|
|
{
|
|
hull.SendHit(Damage*DirectHitDamageMultiplier, Penetration, Spread, DamageType, SourceEntity, hit, forward);
|
|
transform.position = hit.point;
|
|
StartCoroutine(Kill());
|
|
}
|
|
}
|
|
else// if (hit.transform.gameObject.layer == 1)
|
|
{
|
|
StartCoroutine(Kill());
|
|
return;
|
|
}
|
|
|
|
if (HitEffect != null)
|
|
{
|
|
var ht = HitEffect.Instantiate<Transform>();
|
|
ht.SetParent(hit.collider.transform);
|
|
ht.position = hit.point;
|
|
return;
|
|
}
|
|
}
|
|
|
|
transform.position += Velocity * Time.deltaTime;
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
IEnumerator Kill()
|
|
{
|
|
_alive = false;
|
|
var startTime = Time.time;
|
|
var lifetime = Trail.time;
|
|
while (Time.time - startTime < lifetime)
|
|
yield return null;
|
|
GetComponent<Prototype>().ReturnToPool();
|
|
}
|
|
}
|