0
我深化發展汽車發動機劇本,我想用光線投射避開障礙物。問題是,當我把光線投射它指向(0,0,0)世界座標,雖然我所提到的方向,從我的對象是向前。在Unity3d,我的光線投射始終指向(0,0,0)世界座標
public float sensorLength = 10f;
public float frontSensorPosition = 3.65f; // distance from the center of
//the car to its front
public float frontSideSensorPosition = 1.1f;
private void FixedUpdate() {
Sensors();
ApplySteer();
Drive();
CheckWayPointDistance();
}
private void Sensors()
{
RaycastHit hit;
Vector3 sensorStartPos = transform.position;
sensorStartPos.z += frontSensorPosition;
Vector3 fwd = transform.TransformDirection(Vector3.forward);
if (Physics.Raycast(sensorStartPos, fwd, out hit, sensorLength))
{
}
Debug.DrawLine(sensorStartPos, hit.point, Color.green);
}
輸出是這樣的: https://i.imgsafe.org/00/0038d11730.png
我甚至都不需要我的編輯知道,這個工程將畫紅線。 – Draco18s
不幸的是,還有另一個問題。 –
我用障礙物包圍了我的車,看是否顯示它碰到了水手。並最終沒有看到碰撞。 布爾障礙物= Physics.Raycast(sensorStartPos,FWD,出命中,sensorLength); 的debug.log( 「OBSTACLE:」 +障礙); 它始終顯示錯誤。 –