首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用Nav Mesh Agent制作跳跃玩家模型

如何用Nav Mesh Agent制作跳跃玩家模型
EN

Stack Overflow用户
提问于 2017-10-09 22:47:33
回答 1查看 2.1K关注 0票数 0

我有一个带有导航网格代理的播放器模型上的程序代码,允许它在点击时环游世界,但我试图让它跳跃,但似乎还没有实现。

这是我的代码,不知道要添加或删除什么

代码语言:javascript
复制
public class WorldInteraction : MonoBehaviour {
NavMeshAgent playerAgent;

// Use this for initialization
void Start () {
    playerAgent = GetComponent<NavMeshAgent> (); //instantiate the nav mesh to PlayerAgent
}

// Update is called once per frame
void Update () {
    if (Input.GetMouseButtonDown (0) && !UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject ()) //condition if the postion is being clicked on a UI is veung clicked
    {
        GetInteraction (); //call interaction method
    }
    if (Input.GetMouseButtonDown (1) && !UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject ()) 
    {
        transform.Translate (Vector3.up);
    }
}
void GetInteraction(){ //this method gets the ray or point clicked and move the player to that point
    Ray interactionRay = Camera.main.ScreenPointToRay (Input.mousePosition); //get the point clicked in the world
    RaycastHit interactionInfo; //keeps track of the point clicked
    if (Physics.Raycast (interactionRay, out interactionInfo, Mathf.Infinity)) //get the point clicked, store it in InteractionInfo and make sure its not out of range by mathf 
    { 
        GameObject interactedObject = interactionInfo.collider.gameObject;
        if (interactedObject.tag == "Interactable Item") //check if the item point selected is interacrable(cant be move over)
        {
            interactedObject.GetComponent<Interactable> ().MoveToInteraction (playerAgent); //move playerAgent to the Interactable item, so they could interact(its calling the movetoInteractable method in Interactable class).
        } else {
            playerAgent.stoppingDistance = 0;
            playerAgent.destination = interactionInfo.point; //if its a movable point, player destination is set to that point
        }
    } 

}

}

EN

回答 1

Stack Overflow用户

发布于 2017-10-10 00:00:48

NavMeshAgent在所有方向上控制对象,因此它将覆盖您的跳跃尝试。使带有NavMeshAgent的对象成为空对象的子对象,并向上平移该空对象。希望这能有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46649225

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档