안녕하세요 마법사, 난 당신이지도를있는 적을 공격 할 수있는 3D 첫번째 사람 RPG를 만들고있어3D 유니티 C#을 적은 벽을 통해 인터넷의
을 안내합니다. 현재 스크립트가 잘 작동하고 있지만 한 가지 문제가 있습니다. 플레이어가 플레이어에게 집중할 때마다 적을 벽을 통해 걷고 있습니다.
이 문제를 해결하기 위해 이미 몇 가지 시도를했지만 불행히도 결과가 없습니다. 누구든지이 문제에 대한 해결책을 알고 있습니까?
미리 감사드립니다.
goblinAttack.cs :
using UnityEngine;
using System.Collections;
public class goblinAttack : MonoBehaviour {
public Transform player;
static Animator anim;
// Use this for initialization
void Start()
{
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
Vector3 direction = player.position - this.transform.position;
float angle = Vector3.Angle(direction,this.transform.forward);
if(Vector3.Distance(player.position, this.transform.position) < 10 && angle < 30)
{
direction.y = 0;
this.transform.rotation = Quaternion.Slerp(this.transform.rotation,
Quaternion.LookRotation(direction), 0.1f);
anim.SetBool("isIdle",false);
if(direction.magnitude > 5)
{
this.transform.Translate(0,0,0.10f);
anim.SetBool("isRunning",true);
anim.SetBool("isAttacking",false);
anim.SetBool("isCrying",true);
}
else
{
anim.SetBool("isAttacking",true);
anim.SetBool("isRunning",false);
anim.SetBool("isCrying",false);
}
}
else
{
anim.SetBool("isIdle", true);
anim.SetBool("isRunning", false);
anim.SetBool("isAttacking", false);
anim.SetBool("isCrying",false);
}
}
}
NPC 설정 : IsKinematic is not affected by Forces, collisions or joints.으로 표시된 강체가 명심
당신이 당신의 벽 객체에 메쉬 입자 가속기가 있습니까? –
플레이어에게 합법적 인 경로를 찾으려면 길 찾기를 수행해야합니다. 그렇지 않으면 고블린은 플레이어에서 직접 실행을 시도합니다. 이는 도중에 방해받을 가능성이있는 장애물을 통해 중도에 들려서 또는 달리기를 의미합니다. – Abion47
예, 있습니다. 그러나 그것은 여전히 벽을 통해 움직입니다. –