- Home /
How to make car AI using WheelColliders turn exactly 90 degrees?
Hi,
I am making a car AI and I want it to make a perfect 90 degree turn. However I always end up at a slightly off angle and it starts going off the road.
I am using a trigger to tell when the car needs to turn and I pass the direction of the turn
My current code:
public class Turn : MonoBehaviour {
public float turnRadius;
public Direction ifZeroDirection;
public enum Direction {
Left,
Right
}
private void OnTriggerEnter(Collider other) {
SimpleCarController car = other.transform.root.GetComponent<SimpleCarController>();
//car.ReduceSpeed(5);
car.Steer(turnRadius, ifZeroDirection);
}
}
SimpleCarController Steer function:
public void Steer(float angle, Turn.Direction ifZeroDirection) {
turning = true;
newAngle = angle;
float steering = 0.5f;
if (ifZeroDirection == Turn.Direction.Right) addSteering = steering;
else addSteering = -steering;
}
addSteering is basicly float steering = maxSteeringAngle * addSteering;
which is the` axleInfo.rightWheel.steerAngle = steering;`
Comment
Your answer
Follow this Question
Related Questions
gentle turning of the car 0 Answers
Steering Overcompesation 0 Answers
Why won't my car steer? 1 Answer
How to make an AI of a car to jump if there is any obstacle 2 Answers
Wheel Collider Friction problems 1 Answer