Unity_Train/Assets/Player/PlayerController.cs

51 lines
No EOL
1.2 KiB
C#

using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerController : MonoBehaviour
{
private Rigidbody m_Rigidbody;
private Camera m_Camera;
private bool m_IsGrounded = false;
private bool m_WantJump = false;
private Vector2 m_MoveInput = Vector2.zero;
private Vector2 m_LookInput = Vector2.zero;
private Vector3 m_Velocity = Vector3.zero;
private float m_MovementSmoothing = .05f;
private bool m_isColliding = false;
void Awake()
{
m_Rigidbody = GetComponent<Rigidbody>();
m_Camera = GetComponent<Camera>();
}
void FixedUpdate()
{
m_IsGrounded = false;
RaycastHit hit; // TODO: Use to see if on train later and ground angle if that's relevant
if (Physics.Raycast(transform.position, Vector3.down, out hit, 1.1f))
{
m_IsGrounded = true;
}
}
void OnJump()
{
if (m_IsGrounded)
{
m_Rigidbody.AddForce(new Vector3(0f,400f,0f));
m_IsGrounded = false;
}
}
void OnMove(InputValue value)
{
m_MoveInput = value.Get<Vector2>();
}
void OnLook(InputValue value)
{
m_LookInput = value.Get<Vector2>();
}
}