1,三维空间中角色朝向鼠标位置
public void Turn()
{
Ray ray=Camera.main.ScreenPointToRay(Input.MousePosition);
Vector3 vector=player.transform.position-Camera.main.transform.position;
Vector3 direction=(vector.y/ray.direction.y)*ray.direction-vector;
player.transform.LookAt(player.transform.position+direction);
}
2,将某个向量映射到另一个三维空间(transform,right为x轴,up为y轴,forward为z轴)中
public Vector3 Remap(Vector3 source)
{
float x=Vector3.Dot(transform.right,source);
float y=Vector3.Dot(transform.up,source);
float z=Vector3.Dot(transform.forward,source);
return new Vector3(x,y,z);
}
网友评论