• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
Question by BerlinBerlin · Sep 09, 2021 at 08:54 AM · errorerror messagefloatxboxcontroller

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

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:<set_onUpdate>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:<set_onUpdate>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<float>() * brakeTorque;
     }
 
     void GetAngleInput(InputAction.CallbackContext context)
     {
         angle = context.ReadValue<float>() * maxAngle;
     }
 
     void GetTorqueInput(InputAction.CallbackContext context)
     {
         torque = context.ReadValue<float>() * maxTorque;
     }
 
     private void OnEnable()
     {
         handBreakInputAction.Enable();
             steeringInputAction.Enable();
         accelerationInputAction.Enable();
     }
 
     void Start()
     {
      m_Wheels = GetComponentsInChildren<WheelCollider>();
       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<Rigidbody>();
         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.

Comment

People who like this

0 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

212 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

error CS1525: Unexpected symbol `float' 1 Answer

[Begginer] [Solved] How to solve a Null Reference Exception 1 Answer

error CS0111: Type 'AutoEaterBuy' already defines a member called 'Update' with the same parameter types 1 Answer

Help with the Official 2D Roguelike Tutorial from YouTube? 1 Answer

Getting an error: Assertion failed on expression: 'SUCCEEDED(hr)' 5 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges