0
Ive는 장애물 주위를 돌아 다니더라도 항상 플레이어를 바라 보는 것이지만 문제가있는 유일한 문제는 여기에 있습니다. 지터. 레이 캐스트가 장애물에 부딪히지 않고 동시에 플레이어쪽으로 움직이게한다면 어떻게 플레이어를 볼 수 있는지 궁금합니다. 어떤 도움 는 현재 unity3D 작업, 감상 할 수레이크 캐스트가 장애물을 치지 않는 경우에만 플레이어를 봅니다.
using UnityEngine;
using System.Collections;
public class enemyAI : MonoBehaviour
{
public Transform target;
public float moveSpeed;
public float rotationSpeed;
public float minDistance = 0.5f;
public static enemyAI enemyAIself;
RaycastHit hit;
void Awake()
{
enemyAIself = this;
}
void Start()
{
GameObject goTo = GameObject.FindGameObjectWithTag("Player");
target = goTo.transform;
}
void Update()
{
Vector3 dir = (target.position - transform.position).normalized;
if (Physics.Raycast(transform.position, transform.forward, out hit, 5.0f, (1<<8)))
{
Debug.DrawRay(transform.position, hit.point, Color.blue);
dir += hit.normal * 50;
}
Vector3 leftR = transform.position;
Vector3 rightR = transform.position;
leftR.x -= 2;
rightR.x += 2;
if (Physics.Raycast(leftR, transform.forward, out hit, 5.0f, (1<<8)))
{
Debug.DrawRay(leftR, hit.point, Color.blue);
dir += hit.normal * 50;
}
if (Physics.Raycast(rightR, transform.forward, 5.0f, (1<<8)))
{
Debug.DrawRay(rightR, hit.point, Color.blue);
dir += hit.normal * 50;
}
Quaternion rot = Quaternion.LookRotation(dir);
transform.rotation = Quaternion.Slerp(transform.rotation, rot, rotationSpeed * Time.deltaTime);
if (Vector3.SqrMagnitude(target.position - transform.position)> (minDistance * minDistance))
{
//move towards the target
transform.position += transform.forward * moveSpeed * Time.deltaTime;
}
}
}
답장을 보내 주셔서 감사합니다. iam이 웨이 포인트 atm을 만드는 방법을 연습하려고합니다. – user2807944