Unity3D-NavMeshAgent pathfinding

Source: Internet
Author: User

In the morning, I made an automatic tracing function for monster.

OK. paste the following online information about the attributes and methods of navmeshagent.

There are two main types of U3D built-in pathfinding components: navmesh and navmeshagent. The former is used to set the pathfinding network, and the latter is used to set the pathfinding object. Methods To make public in navmesh include:

Raycast traces the rays between two points in navmesh.
Calculatepath calculates the path and storage path between two points.
Distancetoedge finds the navmesh edge closest to a point.
Sample sampleposition to navmesh with the closest point.
Setlayercost sets the cost to exceed the geometric traversal of All proxy types on one layer.
Getlayercost obtains geometric traversal of All proxy types at a layer that exceeds the cost.
Getnavmeshlayerfromname returns a named layer-by-layer index.


In addition, it inherits some variables.

Name of the object.
Hideflags if the object is hidden, is it stored by the user on site or modified?


Inherited Functions
Getinstanceid returns the instance id of the object.
Tostring returns the name of the game object.


Inherited Class Functions
Does the operator bool object exist?
Instantiate: clones the original object and returns the cloned object.
Destroy deletes a game object, component, or asset.
Destroyimmediate: destroys the object OBJ immediately. We strongly recommend that you do not use destruction.
The list type of all activity-loaded type objects returned by findobjectsoftype.
The object type to be loaded for the first activity type returned by findobjectoftype.


Operator = compare if two objects point to the same
Operator! Comparison, if two objects refer to different objects
Dontdestroyonload automatically loads a new scenario when the object's target is not damaged.

Methods To make public in navmesh include:

Variable
Destination navigation toward the destination.
Stoppingdistance stops the position from the target within this distance.
The current speed of the velocity navmesh Proxy component.
Next position in the nextposition path.
The remaining distance in the current path of remainingdistance.
Baseoffset has the relative vertical displacement of Game objects.
The isonoffmeshlink agent is currently located at offmeshlink.
Autotraverseoffmeshlink automatically moves to and off offmeshlinks.
Autorepath tries to get a new path. If the existing path becomes invalid
The haspath proxy currently has a path.
Pathpending is calculating the path, but it is not ready yet
The current ispathstale path is outdated.
Pathstatus: query the status of the current path.
Walkablemask specifies that the navmesh layer is not satisfactory (bit domain ). Change ableablemask to change the old path (see ispathstale)
Speed: Maximum speed of movement.
Angularspeed maximum speed (deg/s ).
Maximum Acceleration
Updateposition: if the agent updates the transformed position.
Updaterotation if the proxy updates the conversion direction.
Radius proxy radius.
Height the height of the proxy.
Obstacleavoidancetype avoids quality level


Function
Setdestination: set or update the target. This triggers a new path calculation.
Activatecurrentoffmeshlink enable or disable the current ?? Link.
Getcurrentoffmeshlinkdata extracts the current offmeshlink status.
Getcurrentoffmeshlinkgameobject refer to the current offmeshlink game object.
Completeoffmeshlink terminates the current offmeshlink.
Move the current position to apply relative motion.
Stop stop the movement of the agent along the current path.
The resume motion follows the current path.
Resetpath clears the current path. Note that the agent will start looking for a new path until setdestination is called.
Setpath specifies the proxy path.
Distancetoedge finds the nearest navmesh edge.
Raycast tracks the navmesh of a target position. Do not move the proxy.
Samplepathposition sample along the current path position.
Setlayercost is set to the geometric traversal cost of the above layer type.
Getlayercost gets the geometric traversal cost that exceeds this layer type.

Inherited Member
Inherited Variables
Enabled enables behaviours update, and disable behaviours.
Transform transform connects to this game object (null, if not connected ).
The Rigidbody rigid body is connected to this game object (null, if not ).
Camera the camera connects to this game object (null, if there is no additional ).
Light: The light connection of the game object (if there is no blank connection ).
The animation is connected to this game object (null, if there is no attachment ).
Constantforce connects to this game object (null, if not connected ).
The Renderer connects to this game object (empty; if not attached ).
Audio audiosource attaches a game object (null, if not connected ).
Guitext connects to this game object (null, if not ).
Networkview connects to this game object (read-only ). (Null; if no connection exists)
Guitexture connects to this game object (read-only ). (Null; if no connection exists)
Collider is connected to this game object (empty; if not attached ).
Hingejoint connects to this game object (null, if not connected ).
The participant emitter is connected to the game object (null, if not ).
The participant system is connected to the game object (null, if not ).
Gameobject this component connects to the target of the game. A component is always connected to a game object.
Tag The identifier of the game object.
Name of the object.
Hideflags if the object is hidden, is it stored by the user on site or modified?

Inherited Functions
If one of the objects in the competition is attached, getcomponent is empty. If it does not return the type of component type.
The type of component returned by getcomponentinchildren is a game object of the type or any child who uses a deep-first search.
Getcomponentsinchildren returns all component types of the type in a game object or any of its children.
Getcomponents returns all types of component-type game objects.
Comparetag is this the tag of the game object?
Sendmessageupwards calls the naming method methodname. Each monobehaviour is an ancestor of the object's behavior in this competition.
The sendmessage function calls the named method methodname. Each monobehaviour is in this game object.
Broadcastmessage calls the named method methodname. Each monobehaviour is an object in this competition or any of its children.
Getinstanceid returns the instance id of the object.
Tostring returns the name of the game object.


Inherited Class Functions
Does the operator bool object exist?
Instantiate: clones the original object and returns the cloned object.
Destroy deletes a game object, component, or asset.
Destroyimmediate: destroys the object OBJ immediately. We strongly recommend that you do not use destruction.
The list type of all activity-loaded type objects returned by findobjectsoftype.
The object type to be loaded for the first activity type returned by findobjectoftype.
Operator = compare if two objects point to the same

To link http://www.j2megame.com/html/xwzx/ty/4110.html

Pathfinding Tutorial:

Http://blog.csdn.net/janeky/article/details/17457533


Okay. The following is my own code.

Using unityengine; using system. collections;/** monster path sourcing Code */public class monster_nav: monobehaviour {private navmeshagent; private gameobject hero; // target point private vector3 targetpos; // record the remaining private float distance = 0; // use this for initializationvoid start () {agent = getcomponent <navmeshagent> (); hero = gameobject. find ("Sam");} // update is called once per framevoid Update () {targetpos = new vector3 (hero. transform. position. x, transform. position. y, transform. position. z); transform. lookat (targetpos); agent. setdestination (targetpos); // debug. log (agent. remainingdistance); // play the animation to determine whether it has reached the destination, play the idle or running animation // The stopping distance is set to 0.5, so the animation cannot be stopped with a remaining distance of 0. // the remaining distance of the current frame is the same as the remaining distance at this time, which indicates monster if (agent. remainingdistance = distance) {animation. play ("wait");} else {distance = agent. remainingdistance; animation. play ("walk ");}}}

Thank you! Haha

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.