我是一個真正的菜鳥,我是一個剛開始編程的藝術家,并且已經四處尋找解決方案,我能找到的最接近的是一個與我的問題相同的 reddit 帖子,但即使沒有人可以找到一個解法。
我已經設定了一個影片控制器,并為它提供了我需要的所有引數,例如行走、跑步、跳躍等。如果我使用播放器控制器腳本,一切都會像魅力一樣作業。現在,當我想把這個角色變成一個 NPC 并放置我從統一手冊中挑選的巡邏 AI 腳本時,事情就不正常了。
我已經烘焙了我的導航網格,我也添加了 NavMeshAgent 組件。NPC 左右滑動,但影片不播放
using UnityEngine;
using UnityEngine.AI;
using System.Collections;
public class Patrol : MonoBehaviour
{
Animator animator;
public Transform[] points;
private int destPoint = 0;
private NavMeshAgent agent;
void Start()
{
animator = GetComponent<Animator>();
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()
{
animator.SetBool("isRunning", true);
// Choose the next destination point when the agent gets
// close to the current one.
if (!agent.pathPending && agent.remainingDistance < 0.5f)
GotoNextPoint();
}
}
影片師截圖
uj5u.com熱心網友回復:
Animator 從默認狀態(以橙色表示)開始,并在此基礎上發生過渡。根據您的影片師的螢屏截圖,影片師可以從您的默認狀態進入空閑、SwordSlash 和 SwordJump 狀態,并且在空閑狀態和運行狀態之間沒有過渡。不過,您的代碼將 isRunning 布林值設定為 true。如果你想讓它作業,你必須將 isWalking bool 設定為 true,這樣影片師就會進入 SwordWalk 狀態。從那里您可以將 isRunning 設定為 true 以轉到運行影片。另一種方法是將isRunning改為isWalking(順便建議你研究一下1D blend trees)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/512422.html
下一篇:查找兩點之間的路徑范圍
