Unity3d pathfinding function Introduction and project demonstration

Source: Internet
Author: User

Pathfinding in Unity3d, you can use the Astarpath pathfinding plugin. It is now possible to use Unity's own Navigation functionality.

To do an example:


In the above picture, Cube is a block object, the ball is to represent the player, to find the way.


Set cube as a non-pass object

First we click on the Window-navigation window and then select 4 cubes, set these 4 cubes as not to pass, then bake



Set the ground to be passed, and then bake


We add control scripts to the Orb, our main character.

Using unityengine;using System.collections;public class Findpath:monobehaviour {public    navmeshagent agent;    Vector3 Point;    Ray Aray;    Raycasthit ahit;//Use the-initializationvoid Start () {}//Update is called once per framevoid update () {if (Input. Getmousebuttondown (0)) {        Aray = Camera.main.ScreenPointToRay (input.mouseposition);        if (Physics.raycast (aray,out ahit))        {point            = Ahit.point;        }        Agent. Setdestination (point);}}}

Get the ball to the mouse click on the place to find the road effect


Unity3d pathfinding function Introduction and project demonstration

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.