x


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);
more ▼

asked Jul 08 '12 at 08:17 PM

maryrall gravatar image

maryrall
1 1 1

(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x956
x416
x286
x48
x30

asked: Jul 08 '12 at 08:17 PM

Seen: 321 times

Last Updated: Jul 08 '12 at 08:17 PM