Aetheria/Assets/Scripts/Gameplay/TractorBeam.cs
Reinier Vens 11a55e236b Loot
Fixed: unable to undock with an aetheric drive (game requires locomotion)
Entities have a chance of dropping any item on board when killed
Mine behavior generalized to grid objects, used in dropped loot
Added tractor beam (not itemized yet) which pulls in nearby loot (and mines!)
Items are added to player inventory when they collide with the ship (and mines explode!)
Added console command to spawn turret
2021-04-15 04:25:22 +01:00

33 lines
No EOL
1.1 KiB
C#

using System;
using UnityEngine;
public class TractorBeam : MonoBehaviour
{
public ParticleSystem ParticleSystem;
public float Radius;
public float Traction;
public float Distance;
public float Power { get; set; }
public Vector3 Direction { get; set; }
public void Update()
{
transform.rotation = Quaternion.LookRotation(Direction);
var emission = ParticleSystem.emission;
if (Power > .01f)
{
var objectFound = false;
foreach (var o in Physics.SphereCastAll(transform.position, Radius, Direction, Distance, 1 << 21))
{
var gridObject = o.collider.GetComponent<GridObject>();
if (gridObject == null) continue;
objectFound = true;
gridObject.Velocity += Vector3.Normalize(transform.position - gridObject.transform.position) * (Traction * Time.deltaTime);
}
emission.rateOverTimeMultiplier = objectFound ? Power : 0;
}
else emission.rateOverTimeMultiplier = 0;
}
}