【发布时间】:2016-09-27 21:22:15
【问题描述】:
我知道如何阻止我的 NPC 与玩家发生碰撞,但我似乎不知道如何让他们停止与玩家发生碰撞?
NPC有一个“AI”的标签,我已经尝试了一些东西,但我真的想不通?
这是我的代码,不胜感激。
using UnityEngine;
using System.Collections;
public class AI : MonoBehaviour {
public Transform target;
public int moveSpeed = 5;
public int rotationSpeed = 2;
public Transform myTransform;
public float minDistance = 0.1f;
void Awake ()
{
myTransform = transform;
}
void Start ()
{
target = GameObject.FindWithTag ("Player").transform;
}
void Update ()
{
Vector3 Distance = target.position - myTransform.position;
if(Distance.sqrMagnitude>minDistance*minDistance)
{
myTransform.rotation = Quaternion.Slerp (myTransform.rotation, Quaternion.LookRotation (target.position - myTransform.position), rotationSpeed * moveSpeed * Time.deltaTime);
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
【问题讨论】:
-
你的意思是他们应该能够互相通过吗?还是完全避开?
-
我的意思是对所有的NPC都设置了距离,并且与玩家保持距离,当他们接近玩家时,他们都会聚集在一起,我想尝试与玩家保持距离所有 NPC 和类似 1 的玩家你能帮忙吗? :)