- Home /
Steering Overcompesation
I have a car and trying to implement an AI System however when I tell the car to travel to a certain waypoint the car begins to overturn due to the drifting and makes a wave continuing to overcompensated the turn. I need to smooth out the turn. Any ideas how to make a gradual turn to a point.
Vector3 target = waypoints[currentWaypoint].position;
Vector3 moveDirection = target - transform.position;
Vector3 localTarget = transform.InverseTransformPoint(waypoints[currentWaypoint].position);
//Calculate the angle for the car tires to travel
m_targetAngle = Mathf.Atan2(localTarget.x, localTarget.z) * Mathf.Rad2Deg;
if (currentAngle < m_targetAngle)
{
currentAngle = currentAngle + (Time.deltaTime * steeringSpeed);
if (currentAngle > m_targetAngle)
{
currentAngle = m_targetAngle;
}
}
else if (currentAngle > m_targetAngle)
{
currentAngle = currentAngle - (Time.deltaTime * steeringSpeed);
if (currentAngle < m_targetAngle)
{
currentAngle = m_targetAngle;
}
}
aiSteerAngle = Mathf.Clamp(currentAngle, (-1) * m_currentMaxSteerAngle, m_currentMaxSteerAngle);
Comment
Your answer
Follow this Question
Related Questions
Steering an AI vehicle to a waypoint using float of -1 to 1? 1 Answer
How to make car AI using WheelColliders turn exactly 90 degrees? 0 Answers
Most Efficient Method for Steering for Vehicle AI 1 Answer
steerAngle keeps the wheel spinning 0 Answers
How to make an AI of a car to jump if there is any obstacle 2 Answers