1
Nav Mesh Agentを持つPlayerモデル上にプログラムコードがありますが、クリックすると世界中を歩くことができますが、飛び越えようとしていますそれを達成する。Nav Mesh Agentを使用してPlayer Modelをジャンプさせる方法
これは私のコードで、それだけでジャンプするあなたの試みを上書きしますのでNavMeshAgentがすべての方向にオブジェクトを制御するもので
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
}
}
}
}
プレーヤーモデルにnavmeshagentとその空のオブジェクトの子がありますが、それでも動きませんでした...コードや関連するもので助けてくれますか?それは私のために働いていない –
私は、transform.Translate(Vector3.up * Time.deltaTime * 50、Space.World); –
ジャンプしましたが、速くて気づかなかった –