J'ai un code de programme sur un modèle de joueur avec Nav Mesh Agent qui lui permet de marcher autour du monde lorsqu'il est cliqué, mais je suis en train de le faire sauter et ne semble pas parvenir.Comment faire un modèle de joueur avec Nav Mesh Agent pour sauter
c'est mon code, je ne sais pas quoi ajouter ou supprimer
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
}
}
}
}
le modèle de joueur a le navmeshagent dessus et c'est un enfant d'un objet vide mais pourtant il n'a pas bougé ... Pouvez-vous m'aider avec un code ou quelque chose lié? parce que cela ne fonctionne pas pour moi –
j'ai essayé ceci, transformer.Translate (Vector3.up * Time.deltaTime * 50, Space.World); –
il a sauté mais était si rapide et n'a pas été remarqué –