- Home /
How do I correct the sensitivity of SteerAngle?
I'm working on a car using WheelColliders. How do I script the WheelColliders so that at high speeds, the SteerAngle decreases in proportion to how fast the car is traveling?
Answer by ckfinite · Nov 22, 2010 at 03:14 AM
Try this:
SteerAngle = Input.GetAxis("Horizontal")*1/rigidBody.velocity
Answer by TroubleMaker · Nov 30, 2012 at 12:57 AM
Bullshit!
rigidbody.velocity is Vector3, Axis input is a float (from 0 to 1) - this can't work!
try with rigidbody.velocity.magnitude, but not like shown above
something like
float maxSteerAngle = 40;
float rv = rigidbody.velocity.magnitude;
if(rv < 10) {
rv = 1;
}
myWheelCollider.steerAngle = Input.GetAxis("Horizontal") * maxSteerAngle * 1 / rv;
but I've not tested this - so don't blame me ;)
Answer by AsclepiiusUnknown · Jul 27, 2020 at 11:35 PM
Hey, this is from ages ago and I didn't even end up using what you suggested but I thought id share my solution. Basically the following makes the steering slower when you get closer to the max amount, allowing easy small turns as well as well planned larger turns.
float anglePct = 100 / (m_MaximumSteerAngle / m_SteerAngle);
float minWaitTime = 5;
if (m_SteerAngle == 0)
{
anglePct = 100 / m_MaximumSteerAngle;
print("");
}
anglePct = Mathf.Abs(anglePct); //Make our number positive if its negaitve
anglePct = Mathf.Clamp(anglePct, minWaitTime, m_MaximumSteerAngle); //Clamp between min and max to reduce initial wait time and avoid extremities
m_SteerAngle = (m_SteerAngle + (steering * Time.deltaTime * anglePct * steerIntensity));
m_SteerAngle = Mathf.Clamp(m_SteerAngle, -m_MaximumSteerAngle, m_MaximumSteerAngle);
The values that arent made either in that code or within the Unity Standard Assets Car Controller.cs are:
steerIntensity - This is a percent value that either increases or decreases the overall time taken to turn. (1 = 'normal')
I also found that unless you drastically increase the max steer angle or mess with these numbers a lot, it can be quite difficult to steer when doing a U-Turn or something else slow. to fix this i did the following which
float slowMag = m_Rigidbody.velocity.magnitude;
if (slowMag < 10)
{
slowMag = slowSteeringEffector;
}
else
{
slowMag = 1;
}
To implement this just replace:
m_SteerAngle = Mathf.Clamp(m_SteerAngle, -m_MaximumSteerAngle, m_MaximumSteerAngle);
with:
m_SteerAngle = Mathf.Clamp(m_SteerAngle, -m_MaximumSteerAngle * slowMag, m_MaximumSteerAngle * slowMag);
Your answer
Follow this Question
Related Questions
How to detect my car is drifting or not ? 1 Answer
Wheel Collider RPM value is flickering between valid value and undefined. 0 Answers
how to find out speed in MPH with wheelcollider.rpm 3 Answers
Why does my game run much faster on Windows than Linux 1 Answer
Animation parameters are not being set 0 Answers