- Home /
Question by
tulloch100 · Jul 02, 2017 at 09:39 AM ·
scripting problemphysicscarsteeringwheels
Connecting steering wheel to front wheels
Hi
I have c# code that allows me to rotate the steering wheel and wheels together and I can move the steering wheel via a slider in the inspector
Code (CSharp):
using System.Collections;
using UnityEngine;
public class SteeringWheelRotation : MonoBehaviour {
[Range(-45f,45f)]
public float steeringWheelRotationAmount = 0f;
public float wheelRotationDampening = 0.5f;
public Transform frontLeftWheel, frontRightWheel;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.eulerAngles = new Vector3 (transform.eulerAngles.x, transform.eulerAngles.y, -steeringWheelRotationAmount);
frontLeftWheel.eulerAngles = new Vector3 (frontLeftWheel.eulerAngles.x, steeringWheelRotationAmount*wheelRotationDampening, frontLeftWheel.eulerAngles.z);
frontRightWheel.eulerAngles = new Vector3 (frontRightWheel.eulerAngles.x, steeringWheelRotationAmount*wheelRotationDampening, frontRightWheel.eulerAngles.z);
}
}
I would like to be able to use the left and right arrow buttons when start the game to move the car
Im very new to coding so could someone show me the right code that would be great
rliocih.jpg
(19.6 kB)
Comment
Your answer
Follow this Question
Related Questions
Strange car beahaviour 0 Answers
Mario Kart-style car Physics 1 Answer
Car physics Problems 1 Answer
Setting Wheelcollider BrakeTorque to 0 does not release brake 0 Answers