简体   繁体   English

在 unity 中,为什么我的角色在使用航点时移动如此奇怪并且一切都口吃?

[英]In unity, Why my character is moving so strange and everything stuttering when using way points?

First a shot video showing how the character is moving.首先是一个显示角色如何移动的拍摄视频。 What i want to do is to make the character to walk not just to move but to walk from one or more given point/s to another point/s.我想要做的是让角色走路不仅仅是为了移动,而是从一个或多个给定的点走到另一个点。

Moving Character Video 移动角色视频

And now what i did so far.现在我到目前为止所做的。

Added to my Hierarchy: Terrain, Main Camera, Directional Light, Cylinder and ThirdPersonController.添加到我的层次结构中:地形、主相机、定向光、圆柱体和第三人称控制器。

In the ThirdPersonController i clicked on the menu: Component > Navigation > Nav Mesh Agent在 ThirdPersonController 中,我单击菜单:Component > Navigation > Nav Mesh Agent

Then dragged to the ThirdPersonController a Patroll.cs script.然后将一个 Patroll.cs 脚本拖到 ThirdPersonController 中。

In the ThirdPersonController Inspector in the Patroll area i added 2 points Walls and Cylinder.在巡逻区域的 ThirdPersonController Inspector 中,我添加了 2 点 Walls 和 Cylinder。 I want the character to walk from the Walls(building) to the Cylinder.我希望角色从墙壁(建筑物)走到圆柱体。 Also in the Patroll area i added to the Agent: ThirdPersonController (Nav Mesh Agent).同样在巡逻区域我添加到代理:ThirdPersonController(导航网格代理)。

Then in the Jierarchy i clicked on the Terrain clicked ot make it static then clicked in the menu on Window > Navigation > Bake and then clicked on the Bake button.然后在 Jierarchy 中,我单击 Terrain 单击 ot 使其静态,然后单击 Window > Navigation > Bake 菜单,然后单击 Bake 按钮。

Then when running the game the character is starting moving automatic in strange way and everything is stuttering.然后在运行游戏时,角色开始以奇怪的方式自动移动,一切都在口吃。 Before added the Patroll script and the Nav Mesh Agent to the ThirdPersonController i could move the character smooth using WSAD keys.在将巡逻脚本和导航网格代理添加到 ThirdPersonController 之前,我可以使用 WSAD 键平滑移动角色。

The goal for now what i want to do is once running the game if i walk using WSAD keys close or touch the walls(building) then the character will start walking automatic to the cylinder position.现在我想要做的目标是一旦运行游戏,如果我使用 WSAD 键关闭或触摸墙壁(建筑物),那么角色将开始自动行走到圆柱体位置。 Or when running the game the character will start walking automatic from it's starting position to the walls and then to the cylinder 3 way points.或者在运行游戏时,角色将开始自动从起始位置步行到墙壁,然后再到圆柱体的 3 个路径点。

This is the Patroll script in c#这是 c# 中的巡逻脚本

using UnityEngine;
using System.Collections;

public class Patroll : MonoBehaviour {

    public Transform[] points;
    private int destPoint = 0;
    public NavMeshAgent agent;

    // Use this for initialization
    void Start () {


        agent = GetComponent<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.Length == 0)
            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.Length;
    }


    void Update () {
        // Choose the next destination point when the agent gets
        // close to the current one.
        if (agent.remainingDistance < 0.5f)
            GotoNextPoint();
    }
}

ThirdPersonController脚本组件包含ThirdPersonController脚本组件时, Patroll它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么当相机是角色的孩子时,只有当按下 W 向前移动时,角色才不会移动,一切都在结结巴巴? - Why when the camera is child of the character only when pressing on W to move forward the character is not moving and everything is stuttering? 在Unity中使用Transform.forward时,角色正在以奇怪的方式移动 - Character is moving in weird ways when using Transform.forward in Unity 在 XNA 应用程序中移动单个精灵时卡顿 - Stuttering when moving a single sprite in an XNA application 使用刚体统一相对于其位置移动角色 - Moving character relative to their location using rigidbody unity 我如何使它在 UI 打开时我的角色/相机停止移动? - How do i make it so my character/camera stops moving when UI is open? 当他站在单击按钮后向上移动的平台上时,为什么ThirdPersonController角色口吃? - Why the ThirdPersonController character is stuttering when he stand on the platform that move up after clicking a button? 为什么我的播放器在 Unity 中在屏幕上向下移动 - Why is my Player moving Down on Screen In Unity Unity Player角色不动 - Unity Player character is not moving 我的角色在2D统一项目中没有前进 - My character is not moving forward in 2d unity project 我的角色自动移动到对面并摔倒(团结) - My character is moving automatically to the opposite side and falling out (UNITY)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM