Hi! First, thank you for reading.
I’m currently following this tutorial, and I’m struggling a lot.
My goal is to have a better understanding of physics behavior in Unity, as well as recreating a fun CarController.
Right now, and thanks to this post in which the issue is very close, I managed to have a car that kind of steers, but weirdly. The car seems to wriggle when using the steer input, but does not really steer, or with huge limitations.
My programming skills are still pretty low, as I’m learning while doing it, so it’s almost a copy of what I saw in the tutorial combined with some handcrafted code. Here is the mess, in case it’s needed.
I think I understood the theorical behavior intended, but I can’t manage to apply it correctly, as I miss a lot of mathematical / logic knowledge for now.
Thanks a lot for whoever is going to answer, have a great day.
private void Steer()
{
foreach (Transform tire in driveTiresPoints)
{
Vector2 initialInputValue = InputManager.Instance.controls.Movement.Steer.ReadValue<Vector2>();
Vector3 inputValue = initialInputValue;
Vector3 steeringDirection = tire.right;
Vector3 tireWorldVelocity = carRigidbody.GetPointVelocity(tire.position);
float steeringVelocity = Vector3.Dot(steeringDirection, tireWorldVelocity);
float desiredVelocityChange = -steeringVelocity * tireGripFactor;
float desiredAcceleration = desiredVelocityChange / Time.fixedDeltaTime;
Vector3 force = desiredAcceleration * tireMass * steeringDirection;
tire.rotation = carRigidbody.transform.rotation * Quaternion.Euler(0, 90 + Mathf.LerpAngle(-40, 40, (-inputValue.x) / 2), 0);
carRigidbody.AddForceAtPosition(force, tire.position);
}
}
Armand Gémeux is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.