using UnityEngine;
using System.Collections;
public class Gazimos : MonoBehaviour
{
public GameObject player;
public GameObject NPC;
void OnDrawGizmos()
{
//绘制x,y,z
Gizmos.color = Color.red;
Gizmos.DrawLine(Vector3.zero, Vector3.right * 1000);
Gizmos.DrawLine(Vector3.zero, Vector3.right * -1000);
Gizmos.color = Color.green;
Gizmos.DrawLine(Vector3.zero, Vector3.up * 1000);
Gizmos.DrawLine(Vector3.zero, Vector3.up * -1000);
Gizmos.color = Color.blue;
Gizmos.DrawLine(Vector3.zero, Vector3.forward * 1000);
Gizmos.DrawLine(Vector3.zero, Vector3.forward * -1000);
//0点到player和NPC
Gizmos.color = Color.black;
Gizmos.DrawLine(Vector3.zero, player.transform.position);
Gizmos.DrawLine(Vector3.zero, NPC.transform.position);
//绘制player到NPC和player正方向,右方向
Gizmos.color = Color.cyan;
Gizmos.DrawLine(NPC.transform .position , player.transform.position);
Gizmos.DrawLine(player.transform.position, player.transform.position+player .transform .forward *3);
Gizmos.DrawLine(player.transform.position, player.transform.position + player.transform.right * 3);
//player到NPC的向量
Vector3 P_N = NPC.transform.position - player.transform.position;
//叉乘
Vector3 P_NF = Vector3.Cross(player.transform.forward , P_N);
Vector3 P_NR = Vector3.Cross(player.transform.right , P_N);
//绘制叉乘的向量 黄色代表左右 灰色代表前后
Gizmos.color = Color.yellow ;
Gizmos.DrawLine(player.transform.position ,P_NF+player.transform .position );
Gizmos.color = Color.gray;
Gizmos.DrawLine(player.transform.position , P_NR+player .transform .position );
}
}
黄色代表左右:
叉乘的y>0时, NPC 在Player 右边
叉乘的y<0时, NPC 在Player 左边
灰色线代表前后:
叉乘的y>0时, NPC 在Player 前边
叉乘的y>0时, NPC 在Player 后边