Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Controller ThumbStick smoothing

Discussion in 'Scripting' started by izoleeted, Aug 4, 2015.

  1. izoleeted

    izoleeted

    Joined:
    Jul 21, 2015
    Posts:
    8
    I'm trying to figure something out, i'm using an XboxOne controller with my car game.

    now using the left thumb stick which is assigned to Horizontal , joystick axis and x axis the tire snaps to the direction i turn (left/right) quickly instead of turning the tire smoothly until it reaches the max angle.
    while using my keyboard input the tire turns smoothly.

    now i can push it smoothly if i push the stick gently to either side but that's not practical.

    my question is, is there a way smooth that action out, going from 0 to 1 smoothly and 0 to -1.
    like an incremental increase instead of snapping to 1 if i push it fast to the right?

    any help is appreciated
     
  2. sz-Bit-Barons

    sz-Bit-Barons

    Joined:
    Nov 12, 2013
    Posts:
    150
    izoleeted likes this.
  3. izoleeted

    izoleeted

    Joined:
    Jul 21, 2015
    Posts:
    8
    Thanks for the response Barons, any idea how would i go to implement that with my input?
    my current input script is as follows..

    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3. using UnityStandardAssets.CrossPlatformInput;
    4. using UnityEngine.Networking;
    5.  
    6. namespace UnityStandardAssets.Vehicles.Car
    7. {
    8.     [RequireComponent(typeof (CarController))]
    9.     public class CarUserControl : NetworkBehaviour
    10.     {
    11.         private CarController m_Car; // the car controller we want to use
    12.  
    13.         private void Awake()
    14.         {
    15.             // get the car controller
    16.             m_Car = GetComponent<CarController>();
    17.         }
    18.  
    19.         private void FixedUpdate()
    20.         {
    21.             // if the player is not a local player return and don't pass controls
    22.             if (!isLocalPlayer)
    23.                 return;
    24.             // pass the input to the car!
    25.             float h = CrossPlatformInputManager.GetAxis("Horizontal");
    26.             float v = CrossPlatformInputManager.GetAxis("Vertical");
    27. #if !MOBILE_INPUT
    28.             if (!isLocalPlayer)
    29.                 return;
    30.             float handbrake = CrossPlatformInputManager.GetAxis("Jump");
    31.             m_Car.Move(h, v, v, handbrake);
    32.             m_Car.Move(h, v, v, 0f);
    33. #endif
    34.         }
    35.     }
    36. }
    37.  
     
  4. izoleeted

    izoleeted

    Joined:
    Jul 21, 2015
    Posts:
    8
    Thanks for the push to the right direction again, I got to mess with it a bit before I had to leave, it partially worked the tires turned smoothly but I did something wrong that the whole position of the car gets shifted to the direction I turn, bad coding on my part, if you post any thing I'll be sure to test when I get back.
     
  5. izoleeted

    izoleeted

    Joined:
    Jul 21, 2015
    Posts:
    8
    i couldn't figure it out still lost i even tried using Lerp that didn't work.