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
This commit is contained in:
parent
c1d632f18a
commit
11a55e236b
56 changed files with 6962 additions and 161 deletions
49
Assets/Scripts/Gameplay/GridObject.cs
Normal file
49
Assets/Scripts/Gameplay/GridObject.cs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
using System;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using static Unity.Mathematics.math;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
public class GridObject : MonoBehaviour
|
||||
{
|
||||
public float RotationSpeed;
|
||||
public float GridOffset;
|
||||
public float GridAttraction;
|
||||
public float Gravity;
|
||||
public float Drag = .1f;
|
||||
public float LaunchDrag;
|
||||
|
||||
private float2 _selfVelocity;
|
||||
private float _timeOffset;
|
||||
|
||||
public Zone Zone { get; set; }
|
||||
public Vector3 Velocity { get; set; }
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_timeOffset = Random.value * 100;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Zone == null) return;
|
||||
|
||||
var t = transform;
|
||||
var position = t.position;
|
||||
var gridHeight = Zone.GetHeight(position.Flatland()) + GridOffset;
|
||||
Velocity += Vector3.up * (sign(gridHeight - position.y) * GridAttraction * Time.deltaTime);
|
||||
Velocity *= max(0, 1 - LaunchDrag * Time.deltaTime);
|
||||
var normal = Zone.GetNormal(position.Flatland());
|
||||
var force = new float2(normal.x, normal.z);
|
||||
var forceMagnitude = lengthsq(force);
|
||||
if (forceMagnitude > .001f)
|
||||
{
|
||||
var fa = 1 / (1 - forceMagnitude) - 1;
|
||||
_selfVelocity += normalize(force) * Zone.Settings.GravityStrength * fa * Gravity;
|
||||
}
|
||||
|
||||
_selfVelocity *= max(0, 1 - Drag * Time.deltaTime);
|
||||
t.position = position + (Velocity + new Vector3(_selfVelocity.x, 0, _selfVelocity.y)) * Time.deltaTime;
|
||||
t.localRotation = Quaternion.Euler(sin(Time.time - _timeOffset * RotationSpeed) * 90, 0, cos(Time.time - _timeOffset * RotationSpeed) * 90);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue