首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我如何连接两个航点系统?

我如何连接两个航点系统?
EN

Stack Overflow用户
提问于 2018-08-27 18:28:03
回答 1查看 104关注 0票数 0

在此处输入代码

代码语言:javascript
复制
List<Transform> points = new List <Transform> ();

private int destPoint = 0;
private UnityEngine.AI.NavMeshAgent agent;

public WaypointSystem path;
//Assembly-CSharp-firstpass
public float remainingDistance = 0.3f;

void Start () {

    points = path.waypoints;

    agent = GetComponent<UnityEngine.AI.NavMeshAgent>();

    // Disabling auto-braking allows for continuous movement
    // between points (ie, the agent doesn't slow down as it
    // approaches a destination point).

       // agent.autoBraking = false;


    //GotoNextPoint();
}


void GotoNextPoint() {
    // Returns if no points have been set up
    if (points.Count == 0)
        return;
    if (destPoint == points.Count) return;

    // Set the agent to go to the currently selected destination.
    agent.destination = points[destPoint].position;


    // Choose the next point in the array as the destination,
    // cycling to the start if necessary.
    //destPoint = (destPoint + 1) % points.Count;
    destPoint = (destPoint + 1);


}


void Update()
{
    // Choose the next destination point when the agent gets
    // close to the current one.
    if (agent.remainingDistance < remainingDistance)
    {
        GotoNextPoint();
    }
   if(destpoint==8)
   agent.enabled=false;


}
}

我想连接两个wayPoint系统。当玩家(智能体)到达第一个wayPoint系统的最后一个点时,它遵循第二个路点,这是可能的吗?在代码中,我在到达第一个路点系统的最后一个点后禁用了导航网格代理,并在几秒钟后启用了它,但玩家返回到第一个waypoint系统的第一个点,它不能跳到第二个点

EN

回答 1

Stack Overflow用户

发布于 2018-08-27 21:22:56

我不熟悉航点系统,但是当您到达最后一个点时,您就不能将您的points变量更改为新的航点系统的waypoints吗(它可以在GotoNextPoint中检查。可能是这样的:

代码语言:javascript
复制
void GotoNextPoint() {
// Returns if no points have been set up
if (points.Count == 0)
    return;
if (destPoint == points.Count)
{
    points = otherPath.waypoints;
    destPoint = 0;
    return;
}

不要忘记将您的destPoint重置为0,这样navmesh代理将从第二个航点系统的第一个元素开始。希望这能有所帮助。

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

https://stackoverflow.com/questions/52037303

复制
相关文章

相似问题

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