I’d like to implement a rotating steering wheel to the players joystick input.
To be honest, I tried THREE HOURS to realize this simple feature, but I’m not really statisfied.
On the first view this one seemed to work
public class SteeringWheelC : MonoBehaviour {
public float maxAngle = 360f;
void Update() {
float angleRotation = Input.GetAxisRaw("Horizontal") * maxAngle;
transform.eulerAngles = new Vector3(angleRotation-90, 60, 90);
}
}
But of course the other two axis doesn’t move, so the car goes to the right and my steering wheel is just fixed on 90 and 60 degrees.
transform.rotation is not really helpful either, because you can only set the speed of rotation.
Could you please give me a hint or something? I don’t expect someone to write a complete script. I just need some advice
Hey there, I was working on a car sim proj using a logitech wheel. the thing is that u’ll have to divide the rotation of the wheel between (-1 to 1) and (-180 to 180) so the the values of Input.GetAxis(“Horizontal”) correspond to the angles of the steering wheel.
I don’t think animations are an effective way to realize this simple feature.
@jeffmorris: this is what I was doing. However, the car moves 90 degress around the x axis but the steering wheel does NOT because you fix it to 0 because of the new Vector3.
@jlcnz :Thanks for your help. I know that page, it’s really helpful, you’re right. Nonetheless I couldn’t find a solution. I guess you miss my point. I only want the steering wheel inside the cars dashboard to move on ONE axis controlled by the steering wheel (Input.GetAxisRaw…).
I need to find a way to lock rotations of 2 axis while only the third one is connected to the GetAxis value. You know, what I mean? You can’t set a new x axis value like “eulerAngles.x = …” because this is a return type only.
Thanks a lot!
EDIT: This keeps making me crazy!! I just want to rotate the steering wheel insinde my car on one axis…
You set the y and z angle to a fixed point ( = 0 ). However, the car is moving to the right and to the left, but the steering wheel remains in the same position.
quick question… are the drivers hands attached to your steering wheel? sounds funny i know… but depending on whether he’s gonna use a driver 3d model or not the solution kind of changes…
This is not what I was talking about, you miss my point. When my car (as a parent) rotates to the left, rotation values of the car change. But the rotation values (the OTHER TWO I don’t want to steer with my axis input) remains in the position 0, because I set them to 0.
i have the same problem here i want to let the steering wheel rotate on the 3 axis (x , y ,z) because if i let it rotate on y axe it’s going everywhere
Wait are you using unity 2018? if so this could be a bug because same is happening with me, all other axis work but y breaks the whole thing and it rotates on every axis for some reason.
This will rotate a transform “steeringWheelTransform” left or right along the horizontal input and stop at the float maxTurnAngle (I used 45f) in either direction no matter the orientation/velocity of the steering wheel’s parent object.
If you are looking for a turning steering wheel based on horizontal input, it is just one line of code.