aboutsummaryrefslogtreecommitdiff
path: root/JamHelper/Assets/JamHelper/JamUtils/FirstPersonCharacterController/Rigidbody/MoveByVelocity/Scripts/GroundChecker.cs
diff options
context:
space:
mode:
Diffstat (limited to 'JamHelper/Assets/JamHelper/JamUtils/FirstPersonCharacterController/Rigidbody/MoveByVelocity/Scripts/GroundChecker.cs')
-rw-r--r--JamHelper/Assets/JamHelper/JamUtils/FirstPersonCharacterController/Rigidbody/MoveByVelocity/Scripts/GroundChecker.cs58
1 files changed, 40 insertions, 18 deletions
diff --git a/JamHelper/Assets/JamHelper/JamUtils/FirstPersonCharacterController/Rigidbody/MoveByVelocity/Scripts/GroundChecker.cs b/JamHelper/Assets/JamHelper/JamUtils/FirstPersonCharacterController/Rigidbody/MoveByVelocity/Scripts/GroundChecker.cs
index 2b2d282..01538e1 100644
--- a/JamHelper/Assets/JamHelper/JamUtils/FirstPersonCharacterController/Rigidbody/MoveByVelocity/Scripts/GroundChecker.cs
+++ b/JamHelper/Assets/JamHelper/JamUtils/FirstPersonCharacterController/Rigidbody/MoveByVelocity/Scripts/GroundChecker.cs
@@ -5,27 +5,49 @@ using UnityEngine;
namespace JamUtils.FirstPersonCharacterController.RigidbodyVelocity
{
- public class GroundChecker : MonoBehaviour
- {
- [SerializeField] private Transform m_Foot;
+ /// <summary>
+ /// 使用碰撞体进行地面检测
+ /// </summary>
+ [RequireComponent(typeof(Collider))]
+ public class GroundChecker : MonoBehaviour
+ {
+ [SerializeField] private Transform m_Foot;
- private List<Collider> m_Colliders = new List<Collider>();
+ private List<Collider> m_Colliders = new List<Collider>();
- public Transform foot
- {
- get
- {
- return m_Foot;
- }
- }
+ public Transform foot
+ {
+ get
+ {
+ return m_Foot;
+ }
+ }
- public bool isOnGround
- {
- get
- {
- return m_Colliders.Count != 0;
- }
- }
+ // 下次物理模拟之前保证有效
+ public bool isOnGround
+ {
+ get
+ {
+ return m_Colliders.Count != 0;
+ }
+ }
+
+
+ /// <summary>
+ /// 是否在斜坡之上
+ /// </summary>
+ public bool isOnSlope
+ {
+ get
+ {
+ RaycastHit hitInfo;
+ if (Physics.Raycast(foot.position, Vector3.down, out hitInfo))
+ {
+ return hitInfo.normal != Vector3.up;
+ }
+ return false;
+ }
+ }
private void OnTriggerEnter(Collider other)
{