unity3d 自动寻路 惯性问题 “滑动”

xiaoxiao2021-02-28  41

自动寻路人物惯性问题,容易滑动,按括号里的来可以解决这个问题

点击往鼠标点到的地方移动脚本ClickToMove.cs

using UnityEngine; using UnityEngine.AI; // Use physics raycast hit from mouse click to set agent destination [RequireComponent(typeof(NavMeshAgent))] public class ClickToMove : MonoBehaviour { NavMeshAgent m_Agent; RaycastHit m_HitInfo = new RaycastHit(); void Start() { m_Agent = GetComponent<NavMeshAgent>(); } void Update() { if (Input.GetMouseButtonDown(0) && !Input.GetKey(KeyCode.LeftShift)) { var ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray.origin, ray.direction, out m_HitInfo)) m_Agent.destination = m_HitInfo.point; } } }
转载请注明原文地址: https://www.6miu.com/read-2627752.html

最新回复(0)