projection test for gallery space w/ chair using squeezed & gnomic projection.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

101 lines
2.2 KiB

using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices.WindowsRuntime;
using Unity.VisualScripting;
using UnityEngine;
public class Treadmill : MonoBehaviour
{
//public Rigidbody m_Body;
public float m_HoldSpeed;
private float m_CurrentForce = 0f;
private float m_angleOffset;
private bool m_RampActive;
public float m_RampTimer;
public float m_RampIncrement;
public float m_HoldSpeedTimer;
public Material m_Belt;
private float m_BeltSpeed;
private void OnEnable()
{
OnChairContact.ApplyTreadmillForce += ApplyForce;
OnChairContact.RemoveTreadmillForce += RemoveForce;
m_angleOffset = 16.6f;
}
private void OnDisable()
{
OnChairContact.ApplyTreadmillForce -= ApplyForce;
OnChairContact.RemoveTreadmillForce -= RemoveForce;
}
public void ApplyForce(Rigidbody rb)
{
Vector3 forceDirection = Quaternion.Euler(0, -m_angleOffset, 0) * Vector3.forward;
if (!m_RampActive && m_RampTimer > 0f)
{
m_RampTimer -= Time.deltaTime;
}
else
{
m_RampActive = true;
}
if (m_RampActive)
{
if (m_CurrentForce > m_HoldSpeed && m_HoldSpeedTimer >= 0)
{
m_HoldSpeedTimer -= Time.deltaTime;
}
else
{
m_CurrentForce += Time.deltaTime * m_RampIncrement;
}
rb.AddForce(forceDirection * m_CurrentForce);
}
}
public void RemoveForce(Rigidbody rb)
{
rb.AddForce(new Vector3(0, 0, 0));
}
private void OnDrawGizmosSelected()
{
// Draw a line representing the force direction
Gizmos.color = Color.red;
Gizmos.DrawRay(transform.position, Quaternion.Euler(0, -m_angleOffset, 0) * Vector3.forward);
}
private void FixedUpdate()
{
m_BeltSpeed += Map(m_CurrentForce, 0, 600, 0, 0.01f);
m_Belt.SetFloat("_Speed", -m_BeltSpeed);
Debug.Log($"{m_BeltSpeed} {m_CurrentForce}");
}
private float Map(float s, float a1, float a2, float b1, float b2)
{
return b1 + (s - a1) * (b2 - b1) / (a2 - a1);
}
}