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.
44 lines
1.1 KiB
44 lines
1.1 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;
|
|
private float m_Force;
|
|
public float m_MaxForce;
|
|
private float m_angleOffset;
|
|
|
|
private void OnEnable()
|
|
{
|
|
m_Force = 0f;
|
|
m_angleOffset = 20f;
|
|
}
|
|
|
|
public void ApplyForce()
|
|
{
|
|
m_Force += 0.1f;
|
|
Vector3 forceDirection = Quaternion.Euler(0, -m_angleOffset, 0) * Vector3.forward;
|
|
m_Body.AddForce(forceDirection * m_Force);
|
|
}
|
|
|
|
public void RemoveForce()
|
|
{
|
|
m_Force = 0;
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
//Debug.Log($"Applying Force {m_Force}");
|
|
m_Force = (m_Force < 0f) ? 0 : (m_Force > m_MaxForce) ? m_MaxForce : m_Force;
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|