光线投射甚至没有给出Debug.Log("it hit something时间,Debug.DrawRay它确实在敌人和玩家之间划清界限。
使用以下脚本的敌人位于“Ignore Raycast”层,它试图击中的玩家位于“Default”层。
void FixedUpdate() {
RaycastHit hit;
Vector2 diff = PlayerMovement.playerTransform.position - transform.position;
Ray raycastToPlayer = new Ray(transform.position, diff);
Debug.Log(raycastToPlayer);
Debug.DrawRay(transform.position, diff, Color.white, 0.01f, true);
if (Physics.Raycast(raycastToPlayer, out hit)) {
Debug.Log("it hit something");
if (hit.collider != null) {
Debug.Log(hit.collider.gameObject.name);
if (hit.transform.tag == "Player"){
float rotZ = Mathf.Atan2(diff.y, diff.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(0f, 0f, rotZ);
}
}
}
}
偶然的你
茅侃侃
相关分类