Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

Issues steering car with Xbox controller. Help needed.,Trouble steering with Xbox controller

$
0
0
Having an issue adding controller support to my game, i have the accelerator working but when it comes to steering it presents this error: "InvalidOperationException while executing 'performed' callbacks of 'Gameplay/SteeringAngle[/XInputControllerWindows/leftStick,/Keyboard/a,/Keyboard/d]' UnityEngine.InputSystem.LowLevel.<>c__DisplayClass7_0:b__0(NativeInputUpdateType, NativeInputEventBuffer*) UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, IntPtr)" and also: InvalidOperationException: Cannot read value of type 'float' from control '/XInputControllerWindows/leftStick' bound to action 'Gameplay/SteeringAngle[/XInputControllerWindows/leftStick,/Keyboard/a,/Keyboard/d]' (control is a 'StickControl' with value type 'Vector2') UnityEngine.InputSystem.InputActionState.ReadValue[TValue] (System.Int32 bindingIndex, System.Int32 controlIndex, System.Boolean ignoreComposites) (at Library/PackageCache/com.unity.inputsystem@1.0.2/InputSystem/Actions/InputActionState.cs:2020) UnityEngine.InputSystem.InputAction+CallbackContext.ReadValue[TValue] () (at Library/PackageCache/com.unity.inputsystem@1.0.2/InputSystem/Actions/InputAction.cs:1433) KartEngine.GetAngleInput (UnityEngine.InputSystem.InputAction+CallbackContext context) (at Assets/KartEngine.cs:62) UnityEngine.InputSystem.Utilities.DelegateHelpers.InvokeCallbacksSafe[TValue] (UnityEngine.InputSystem.Utilities.InlinedArray`1[System.Action`1[TValue]]& callbacks, TValue argument, System.String callbackName, System.Object context) (at Library/PackageCache/com.unity.inputsystem@1.0.2/InputSystem/Utilities/DelegateHelpers.cs:51) UnityEngine.InputSystem.LowLevel.<>c__DisplayClass7_0:b__0(NativeInputUpdateType, NativeInputEventBuffer*) UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, IntPtr) The code: public class KartEngine : MonoBehaviour { [SerializeField] float maxAngle = 30f; [SerializeField] float maxTorque = 300f; [SerializeField] float brakeTorque = 30000f; [SerializeField] GameObject wheelshape; [SerializeField] float topSpeed = 5f; [SerializeField] int stepBelow = 5; [SerializeField] int stepAbove = 1; [SerializeField] DriveType driveType; WheelCollider[] m_Wheels; float handbrake, torque; public float angle; public InputActionAsset inputActions; InputActionMap gameplayActionMap; InputAction handBreakInputAction; InputAction steeringInputAction; InputAction accelerationInputAction; //stable attempt public float cMass = -0.9f; public Vector3 com; public Rigidbody rb; public enum DriveType { RearWheelDrive, FrontWheelDrive, AllWheelDrive } void Awake() { gameplayActionMap = inputActions.FindActionMap("Gameplay"); handBreakInputAction = gameplayActionMap.FindAction("Handbrake"); steeringInputAction = gameplayActionMap.FindAction("SteeringAngle"); accelerationInputAction = gameplayActionMap.FindAction("Acceleration"); handBreakInputAction.performed += GetHandBrakeInput; handBreakInputAction.canceled += GetHandBrakeInput; steeringInputAction.performed += GetAngleInput; steeringInputAction.canceled += GetAngleInput; accelerationInputAction.performed += GetTorqueInput; accelerationInputAction.canceled += GetTorqueInput; } void GetHandBrakeInput(InputAction.CallbackContext context) { handbrake = context.ReadValue() * brakeTorque; } void GetAngleInput(InputAction.CallbackContext context) { angle = context.ReadValue() * maxAngle; } void GetTorqueInput(InputAction.CallbackContext context) { torque = context.ReadValue() * maxTorque; } private void OnEnable() { handBreakInputAction.Enable(); steeringInputAction.Enable(); accelerationInputAction.Enable(); } void Start() { m_Wheels = GetComponentsInChildren(); for ( int i = 0; i < m_Wheels.Length; i++) { var wheel = m_Wheels[i]; if(wheelshape != null) { var ws = Instantiate(wheelshape); ws.transform.parent = wheel.transform; } } rb = GetComponent(); rb.centerOfMass = new Vector3(0, cMass, 0); } // Update is called once per frame void Update() { m_Wheels[0].ConfigureVehicleSubsteps(topSpeed, stepBelow, stepAbove); foreach(WheelCollider wheel in m_Wheels) { if (wheel.transform.localPosition.z > 0) { wheel.steerAngle = angle; } if(wheel.transform.localPosition.z < 0) { wheel.brakeTorque = handbrake; } if(wheel.transform.localPosition.z < 0 && driveType != DriveType.FrontWheelDrive) { wheel.motorTorque = torque; } if(wheel.transform.localPosition.z > 0 && driveType != DriveType.RearWheelDrive) { wheel.motorTorque = torque; } if (wheelshape) { Quaternion q; Vector3 p; wheel.GetWorldPose(out p, out q); Transform shapeTransform = wheel.transform.GetChild(0); if (wheel.name == "a0l" || wheel.name == "a1l" || wheel.name == "a2l" || wheel.name == "") { shapeTransform.rotation = q * Quaternion.Euler(0, 180, 0); shapeTransform.position = p; } else { shapeTransform.position = p; shapeTransform.rotation = q; } } } } } If anyone could help with this that would be awesome! I've tried for a while now and just can't figure it out. Thanks in advance.

Viewing all articles
Browse latest Browse all 2891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>