- Home /
Car steering control
I was doing car tutorial and I found steering control code there ...But the problem is it take turn drastically when i take input as Mathf.Clamp ( Input.GetAxis("Horizontal"),-0.5,0.5);
Please help me to make it steering proper in my car racing game...Below is the reference code
if (steerInput > 0.0f)
{
steering += (steerInput * 30) * Time.deltaTime;
if (steering > steerInput) steering = steerInput;
m_steerR = steerMax * steering;
if (m_steerR > m_steerAngleMax) m_steerR = m_steerAngleMax;
m_steerL = Mathf.Rad2Deg * Mathf.Atan(1.0f / (Mathf.Tan((90 - m_steerR) * Mathf.Deg2Rad) + B / H));
}
else if (steerInput < 0.0f)
{
steering += (steerInput * 30) * Time.deltaTime;
if (steering < steerInput) steering = steerInput;
m_steerL = steerMax * steering;
if (m_steerL < -m_steerAngleMax) m_steerL = -m_steerAngleMax;
m_steerR = -Mathf.Rad2Deg * Mathf.Atan(1.0f / (Mathf.Tan((90 + m_steerL) * Mathf.Deg2Rad) + B / H));
}
else
{
steering = Mathf.Lerp(steering, 0, Time.deltaTime * 30);
m_steerL = steerMax * steering;
m_steerR = steerMax * steering;
}
Answer by roamcel · Nov 05, 2011 at 05:44 AM
The '30' value that you're using around is the intended DAMPING.
So basically, turn that into a variable called
turnspeed
and then assign it a value of 1
and you'll immediately notice the difference in rotation speed!
I changed the value of that ... and i can see the change in my left nd turn ..but Roamcel my car is not running straight when i just keep forward key press my car drags to either left or right depends on the last input ... what to do abt it ? \