public SteeringOutput getSteering() { Vector3 rayVector = s.getCharacter().velocity; rayVector.Normalize(); rayVector *= lookahead; //Debug.Log(lookahead); // Does the ray intersect any objects excluding the player layer collisionDetector = new RaycastHit(); float angleInc = 10f; //Debug.DrawRay(s.getCharacter().position, s.getCharacter().velocity, Color.green); for (int i = 0; i < 6; i++) { Vector3 rotRayVec; if (i % 2 == 0) { rotRayVec = Quaternion.AngleAxis(angleInc * -(i / 2), Vector3.up) * rayVector; } else { rotRayVec = Quaternion.AngleAxis(angleInc * Mathf.Ceil(i / 2), Vector3.up) * rayVector; } rotRayVec.Scale(new Vector3(1f, 0f, 1f)); Debug.DrawRay(s.getCharacter().position, rotRayVec, Color.cyan); s.getCharacter().owner.GetComponent <NPCController>().DrawLine(s.getCharacter().owner.transform.position, rotRayVec * lookahead); if (Physics.Raycast(s.getCharacter().position, rotRayVec, out collisionDetector, lookahead)) { if (collisionDetector.collider.gameObject.Equals(s.getCharacter().owner)) { continue; } Debug.DrawRay(collisionDetector.point, collisionDetector.normal * avoidDistance, Color.red); s.setTargetPosition(collisionDetector.point + (collisionDetector.normal * avoidDistance)); Kinematic avoid = new Kinematic() { position = collisionDetector.point + (collisionDetector.normal * avoidDistance) }; //targetPos = s.getTarget().position; DynamicSeek seekAvoidPoint = new DynamicSeek(s.getCharacter(), avoid, maxAcceleration); return(seekAvoidPoint.getSteering()); } } try { targetPos = s.getTarget().position; } catch (Exception e) { } return(s.getSteering()); }
public SteeringOutput getSteering() { Vector3 rayVector = s.getCharacter().velocity; rayVector.Normalize(); rayVector *= lookahead; //Debug.Log(lookahead); // Does the ray intersect any objects excluding the player layer collisionDetector = new RaycastHit(); float angleInc = 10f; //Debug.DrawRay(s.getCharacter().position, s.getCharacter().velocity, Color.green); for (int i = 0; i < 6; i++) { Vector3 rotRayVec; if (i % 2 == 0) { rotRayVec = Quaternion.AngleAxis(angleInc * -(i / 2), Vector3.up) * rayVector; } else { rotRayVec = Quaternion.AngleAxis(angleInc * Mathf.Ceil(i / 2), Vector3.up) * rayVector; } rotRayVec.Scale(new Vector3(1f, 0f, 1f)); //Debug.DrawRay(s.getCharacter().position, rotRayVec, Color.cyan); if (Physics.Raycast(s.getCharacter().position, rotRayVec, out collisionDetector, lookahead)) { //Debug.DrawRay(collisionDetector.point, collisionDetector.normal * avoidDistance, Color.red); s.setTargetPosition(collisionDetector.point + (collisionDetector.normal * avoidDistance)); targetPos = s.getTarget().position; DynamicSeek seekAvoidPoint = new DynamicSeek(s.getCharacter(), s.getTarget(), maxAcceleration); return(seekAvoidPoint.getSteering()); } } targetPos = s.getTarget().position; return(s.getSteering()); }
public SteeringOutput getSteering() { path.getClosestPointOnPath(path.nodeList[0].transform, path.nodeList[1].transform, s.getCharacter().position); return(new SteeringOutput()); }