[英]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.
我想要做的是让角色走路不仅仅是为了移动,而是从一个或多个给定的点走到另一个点。
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.