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

Cahracter Controller Unity script weird issue

Discussion in 'Scripting' started by opeca, Jan 7, 2018.

  1. opeca

    opeca

    Joined:
    Sep 17, 2013
    Posts:
    19
    Hello All,

    I've just tried to setup a very basic character controller.

    I "copy+paste" the script which is the example on Unity page, but a weird issue came up.

    Code (CSharp):
    1.         void Update()
    2.         {
    3.             var controller = GetComponent<CharacterController>();
    4.             if (controller.isGrounded) {
    5.                 this.moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
    6.                 this.moveDirection = transform.TransformDirection(this.moveDirection);
    7.  
    8.                 this.moveDirection *= this.speed;
    9.  
    10.                 if (Input.GetButton("Jump"))
    11.                     moveDirection.y = jumpSpeed;
    12.             }
    13.             this.moveDirection.y -= this.gravity * Time.deltaTime;
    14.             controller.Move(this.moveDirection * Time.deltaTime);
    15.         }
    It's work fine, but the jump.
    When I press two direction buttons at the same time, it's not working ((Input.GetButton("Jump") condition won't be true) except if I press up + right cursor. (Down+right, down+left, up+left not working)
    Another strange thing if I use the WASD keys, everything works fine.

    Did anybody meets with this issue?

    I'm using Unity 5.6.3

    Thank you!
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Not sure about that issue. I would suggest that you get the component for the character controller in Awake or Start though and re-use rather than fetching it each update.
     
  3. opeca

    opeca

    Joined:
    Sep 17, 2013
    Posts:
    19
    Thank you for your quick reply, but still not working.
    Anyway you're right, it's much better to set it from Start method at once.
     
  4. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Ya, that wasn't meant to solve your issue. Just a different one :)

    This is a long shot, but does changing the event items (i can't remember the name) .. "number of inputs per second" - have any affect?
     
  5. opeca

    opeca

    Joined:
    Sep 17, 2013
    Posts:
    19
    Now I tried it, no effects, no matters if I set it to lower or higher value.
    I also tried to swap main and alternate buttons configuration in InputManager, but didn't works too.
     
  6. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Sorry, ya never heard of this specific issue. Which version of Unity?
    Perhaps you could report it as a bug.
    If you're on an older version you could try updating & see if the issue exists there, too.

    Otherwise, I'm not at all sure, sorry :)
     
  7. opeca

    opeca

    Joined:
    Sep 17, 2013
    Posts:
    19
    I'm using Unity 5.6.3
    Thank you anyway!