wip: Levitation system
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 573fc2a2745da7749946e6c481296f63
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,19 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class LevitationManager : MonoBehaviour
|
||||
{
|
||||
public static LevitationManager Instance { get; private set; }
|
||||
|
||||
[Range(0, 1)] public float Levitation;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
if (Instance == this)
|
||||
Instance = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 42b0f114188437f49b9c825c9af19f89
|
||||
@@ -0,0 +1,74 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class LevitationObject : MonoBehaviour
|
||||
{
|
||||
[System.Serializable]
|
||||
public class References
|
||||
{
|
||||
public Rigidbody Rigidbody;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class Settings
|
||||
{
|
||||
[Range(0, 99)] public int Seed = -1;
|
||||
public Vector3 Offset = new Vector3(0, 3, 0);
|
||||
public Vector3 DivergeanceMin = new Vector3(1, 1, 1);
|
||||
public Vector3 DivergeanceMax = new Vector3(-1, -1, -1);
|
||||
public Vector3 Amplitude = new Vector3(.1f, .5f, .1f);
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class State
|
||||
{
|
||||
[Range(0, 1)] public float Levitating;
|
||||
}
|
||||
|
||||
[SerializeField] private References _references;
|
||||
[SerializeField] private Settings _settings;
|
||||
[SerializeField] private State _state;
|
||||
|
||||
private Vector3 _originPos;
|
||||
private Vector3 _randomAxis;
|
||||
|
||||
void OnValidate()
|
||||
{
|
||||
if (!_references.Rigidbody)
|
||||
_references.Rigidbody = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
_originPos = transform.position;
|
||||
_randomAxis = new Vector3(Random.Range(-1f, 1f), Random.Range(-1f, 1f), Random.Range(-1f, 1f)).normalized;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (!LevitationManager.Instance || LevitationManager.Instance.Levitation <= 0)
|
||||
return;
|
||||
|
||||
_references.Rigidbody.isKinematic = true;
|
||||
_references.Rigidbody.useGravity = false;
|
||||
|
||||
float t = Time.timeSinceLevelLoad;
|
||||
t+= (transform.GetSiblingIndex() + (transform.parent ? transform.parent.GetSiblingIndex() : 0)) * 7.63f;
|
||||
|
||||
float cosT0 = Mathf.Cos(t * .3f);
|
||||
float cosT1 = Mathf.Cos(t);
|
||||
float sinT0 = Mathf.Sin(t * .3f);
|
||||
|
||||
Vector3 offset = _settings.Offset;
|
||||
offset.x += _settings.DivergeanceMin.x * cosT0 + _settings.DivergeanceMax.x * sinT0 * _settings.Amplitude.x;
|
||||
offset.y += _settings.DivergeanceMin.y * cosT1 + _settings.DivergeanceMax.y * cosT1 * _settings.Amplitude.y;
|
||||
offset.z += _settings.DivergeanceMin.z * sinT0 + _settings.DivergeanceMax.z * cosT0 * _settings.Amplitude.z;
|
||||
|
||||
Vector3 targetPos = _originPos + offset;
|
||||
targetPos = Vector3.Lerp(transform.position, targetPos, t / Mathf.Max(Vector3.Distance(transform.position, targetPos) * 4f, 1));
|
||||
targetPos = Vector3.Slerp(_originPos, targetPos, LevitationManager.Instance.Levitation);
|
||||
|
||||
Quaternion targetRot = Quaternion.AngleAxis(t * 10, _randomAxis);
|
||||
|
||||
_references.Rigidbody.Move(targetPos, targetRot);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5e91f8dd05f086146b1c06cf5517f3fb
|
||||
Reference in New Issue
Block a user