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);
asked
Jul 08 '12 at 08:17 PM
maryrall
1
●
1
●
1