car game unity 5
hi, I want to make the steering wheels of my car rotate left or right according to the movement of the car. Please, I need helps. thanks This is the code of the direction of the car to right or left // Direction du vehicule float DA =(((WheelAngleMax - DAmax) / MaxSpeed) Speed ) + DAmax; front_left.steerAngle = Input.GetAxis("Horizontal") DA; front_right.steerAngle = Input.GetAxis("Horizontal") * DA;
I don't know how to make my steering wheel rotate like the front wheels. I really need helps. I search on the internet and I don't find a tutorial to do it
Answer by Honorsoft · Mar 17, 2018 at 10:13 PM
If you check out the Unity's Standard Assets, there is already a car with turning wheels. To add a turning steering wheel, you don't even have to 'mess' with any of the car controller code or anything like that. Just have a separate object as a steering wheel and then you can just add code to the car script that turns the wheel object according to the steering input. What I mean is, the car's wheels are being turned already by Unity's code according to Input by the player, you just want to add a line of code (or two) that rotates the steering-wheel object also (on the Z-axis I think). You could add your code to the CarUserControl.cs script or on the CarController.cs script or just add a script to the SteeringWheel object that checks the horizontal input for it self and rotates itself sccordingly. For example, the CrossPlatformInputManager.GetAxis("Horizontal") is used to turn the tires between -25 and 25 on the Y axis. That is for front wheels (SkyCarWheelFrontLeft and SkyCarWheelFrontLeft in the Heirarchy). I have to study this more too, I am currently adding vehicles to my MMORPG, but it looks like the CarUserControl.cs script checks the player input, and then calls a Move function that resides in the CarController.cs script. (See Maximum Steer Angle in the CarController in the Inspector).
You want to add a MaxTurnAngle variable for your steering wheel (50 looks right to me instead of 25 like the wheels), making sure your SteeringWheel has the correct starting orientation (X-Right,Y-Up,Z-Forward). Then either adjust it's Z rotation according to the player's horizontal (Left and Right) input directly, or you could use Unity's float CurrentSteerAngle
X 2 and apply that amount to the Z rotation of the SteeringWheel.
Your answer
![](https://koobas.hobune.stream/wayback/20220612143510im_/https://answers.unity.com/themes/thub/images/avi.jpg)