点乘叉乘

 

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{

void Update()
{
Setfpos();
}
public Transform duifang;
public void Setfpos()
{
Vector3 delta = duifang.transform.position - transform.position;
//正为前 负为后 点乘
if (Vector3.Dot(transform.forward, delta) > 0)
{
Debug.Log("在前方");
}
else
{
Debug.Log("在后方");
}
//y值为正对方在右边,为负在左边 叉乘
if (Vector3.Cross(transform.forward, delta).y > 0)
{
Debug.Log("在右边");

}
else
{
Debug.Log("在左边");

}

}
}

posted @ 2023-04-05 20:02  天分丶张三  阅读(21)  评论(0编辑  收藏  举报