【发布时间】:2016-07-21 15:46:57
【问题描述】:
PlayerController 类
public LayerMask groundLayer;
void LookRotation()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
if (Physics.Raycast(ray, out hitInfo, groundLayer))
{
destination = new Vector3(hitInfo.point.x, transform.position.y, hitInfo.point.z);
//Look at mouse position
transform.LookAt(destination);
}
}
我在让我的 Raycast 忽略我的玩家或只检测地面时遇到问题。在实际的统一检查器中,我将LayerMask 设置为我的Ground Layer,并且使用我当前的代码,它只会检测到位于Ground Layer 中的地面,尽管玩家仍然会干扰Raycast,即使它是不在Ground Layer 中。我需要 Raycast 完全忽略玩家,即使这是通过将玩家添加到 Ignore Raycast 层来实现的,但我不能这样做,因为玩家需要被不同的 Raycast 检测到。所有这些代码都出现在我的PlayerController 脚本中,因为它用于确定我的玩家轮换,我不确定这是否可能是玩家干扰 Raycast 的原因。提前干杯!
【问题讨论】:
-
谢谢乔,我想出了我的第二个问题。
-
太棒了!回头见……