度々質問してすみません。Andrew Gotow の Car AI に問題があります。問題は、AI が前のプレイヤー/車を避けなかったか、前に進んで前のプレイヤー/車にぶつかったことです。車や障害物にぶつかると、加速を停止したり、動作を停止したりします。
私を助けてください。AIが障害物にぶつからないようにする方法がわかりません
これは私が使用するコードです。助けてくれてありがとう
function GotNewWaypoint(newWay : Vector3, newRot : Quaternion){
wpObj.transform.position = newWay;
wpObj.transform.rotation = newRot;// wpObj is a triggered box collider that sets GotNewWaypoint function everytime AI hits the collider
}
function NavigateTowardsWaypoint(){ // Runs in Update function
var relativePosition : Vector3;
var hit : RaycastHit;
if(!alternativeWaypointer){
relativePosition = transform.InverseTransformPoint(Vector3(wpObj.transform.position.x,transform.position.y,wpObj.transform.position.z));
}else{// turn on alternative position if Spherecast hits object
relativePosition = transform.InverseTransformPoint(Vector3(raycaster*wpObj.transform.position.x,transform.position.y,wpObj.transform.position.z)); // move wpObj on axis x a bit so the AI shouldn't hit the obstacle
}
if(Physics.SphereCast(transform.position,40,transform.forward,hit,30)){
if(hit.transform != this.transform){
if(hit.collider.tag == "Player" || hit.collider.tag == "Opponent" || hit.collider.tag == "Environtment"){
alternativeWaypointer = true;
raycaster = -Vector3.Normalize(hit.point).x * 5;
}else alternativeWaypointer = false;
}
}
inputSteer = relativePosition.x / relativePosition.magnitude;//used for ai's handling control. usually it's 1 or -1
if(Mathf.Abs(inputSteer) < .5){
inputTorque = relativePosition.z / relativePosition.magnitude; //corner is not too tight, accelerate
}else{
inputTorque = 0.0; // corner is too tight, stop accelerating
}
}