This repository has been archived on 2024-11-03. You can view files and clone it, but cannot push or open issues or pull requests.
snakeinabox/Assets/Scripts/Logic/World/Rig.cs
2020-12-13 19:50:58 -08:00

162 lines
No EOL
4.5 KiB
C#

using System;
using UnityEngine;
using UnityEngine.XR;
[Serializable]
public class Rig
{
[HideInInspector]
public World world;
[Header("Design")]
public float scale;
public Vector3 headOffset, pivotPos;
public void Set(InspectorSetter setter)
{
setter.Set("Rig.scale", scale);
setter.Set("Rig.headOffset", headOffset);
setter.Set("Rig.pivotPos", pivotPos);
}
public void Fetch(InspectorSetter setter)
{
headOffset = setter.Fetch("Rig.scale", scale);
headOffset = setter.Fetch("Rig.headOffset", headOffset);
pivotPos = setter.Fetch("Rig.pivotPos", pivotPos);
}
[Header("References")]
public GameObject disconnected;
public Transform rigTransform, head, con, lCon, hangingRod;
public Camera recordCam;
[HideInInspector]
public Quaternion controllerRot = Quaternion.identity;
[HideInInspector]
public Quaternion inputRot = Quaternion.identity;
[HideInInspector]
public Vector3 controllerPos;
public Vector3 boxShake, boxOffset;
public bool alignRecordCam;
public void Start(World world)
{
this.world = world;
Game.OnBump += Bump; // replace these systems...
Game.OnCrash += Bump;
recordCam.gameObject.SetActive(Application.isEditor);
}
Quaternion flipRot = Quaternion.identity;
float flipEuler = 180;
public Lerper lerper;
public void Update()
{
Control control = world.logic.control;
// Apply to Transforms
Quaternion flip = Quaternion.identity;
head.localPosition = control.headset.pos;
head.localRotation = control.headset.rot;
con.localPosition = control.rightHand.pos;
con.localRotation = control.rightHand.rot;
lCon.localPosition = control.leftHand.pos;
lCon.localRotation = control.leftHand.rot;
// °inview
// if (OVRInput.GetDown(OVRInput.Button.PrimaryHandTrigger, ovrCon))
// {
// flipEuler *= -1;
// lerper.t *= -1;
// }
// rig.localScale = Vector3.one * scale;
// Quaternion targetRot = Quaternion.Euler(0, flipEuler, 0);
// if (OVRInput.Get(OVRInput.Button.PrimaryHandTrigger, ovrCon))
// {
// lerper.Update(1);
// }
// else
// {
// lerper.Update(0);
// }
// flipRot = Quaternion.SlerpUnclamped(Quaternion.identity, targetRot, lerper.t);
// rig.rotation = flipRot;
// rig.position = flipRot * -head.localPosition * scale;
// rig.position += pivotPos + (head.rotation * headOffset);
// CONVERT TO LERPER
// Shake
boxShake = Vector3.Lerp(boxShake, (boxShake - boxOffset) * 0.5f, 13 * Time.deltaTime);
boxOffset += boxShake * 13 * Time.deltaTime;
rigTransform.position += boxOffset;
// Hanging Rod
hangingRod.position = pivotPos;
hangingRod.rotation = head.rotation;
// Record Cam
Vector3 twoDir = new Vector3(head.position.x, 0, head.position.z).normalized;
Vector3 recPos = (Quaternion.LookRotation(twoDir) * new Vector3(0.5f, 0.25f, 0.5f).normalized * 40);
if (alignRecordCam)
{
recordCam.transform.position = recPos;
recordCam.transform.rotation = Quaternion.LookRotation(-recPos);
}
// °fullrot
// inputRot = controllerRot = OVRInput.GetLocalControllerRotation(remote);
// point & swipe swap/choose
// both hands? (nah makes point the odd one out)
// HOW TO FILTER OUT THE SPIN CHAIR VEL? (LCON? NAH... BUT MIGHT BE GOOD FOR TESTINGs)
// flip view? what about 90/45 degree snaps ( or drag view!? )
// all oculus bs pulled filtered through a single file
// menu system cull
// PRIORITY
// starting scene! the sooner the better ( break things! )
// refactor like vader life alyx!
// °dragdir
// Vector3 conVel = flipRot * (con.localPosition - oldConPos) / Time.deltaTime;
// OVRInput.SetControllerVibration(0, 0, OVRInput.Controller.RTouch);
// if (OVRInput.Get(OVRInput.Button.PrimaryIndexTrigger, ovrCon))
// {
// if (conVel.magnitude > 0.05f)
// {
// OVRInput.SetControllerVibration(1, 0.1f, OVRInput.Controller.RTouch);
// }
// rawDir = (rawDir + conVel * Time.deltaTime * 30).normalized;
// }
// inputRot = Quaternion.LookRotation(rawDir);
// oldConPos = con.localPosition;
}
Vector3 oldConPos;
Vector3 rawDir = Vector3.forward;
public Vector3Int InputDirection(Main main)
{
Vector3Int newDir = Main.SnapDir((inputRot * Vector3.forward));
// no neck snaps
if (main.snake[0] + newDir != main.snake[1])
{
return newDir;
}
return main.dir;
}
void Bump(Vector3 dir)
{
boxShake -= dir;
}
}