Search Unity

CharacterController - Player glides over ball like a wave - is ChCon broken ?

Discussion in 'Scripting' started by Darjamfar, Jul 7, 2019.

  1. Darjamfar

    Darjamfar

    Joined:
    Jun 4, 2012
    Posts:
    63
    Hi
    I am developing a soccer game with some players moving around using steering behaviours at the moment. I'm using a CharacterController (CC) to move my players. Unfortunately i'm encountering a behavioural problem with said CC and i'm not sure if it's me or Unity.

    This video explains it best.



    I have tried many combinations of settings on the CC: slope limit, step offset, skin width, moving the centre, radius etc. I've tried the step offset and slope limit both at 0 moving up to large numbers and it's the same problem - the player rides over the ball like it's a wave. It's astonishing. To me the ball should bounce off the player. The ball radius 0.11.

    Does anyone know why i'm getting this weirdness ?
     
  2. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    That's because CC attempts to depenetrate colliders by design. Any collider is a potential penetration.

    What you should do instead, is to create a separate layer for the Ball, and disable the collision between Player and Ball completely (via Project Settings -> Physics -> Collision matrix).

    Then, handle the collision between them manually as you desire, be it bouncing, or any other behaviour.
     
  3. Darjamfar

    Darjamfar

    Joined:
    Jun 4, 2012
    Posts:
    63
    Thank you for your reply.

    I had the ball/players on a separate layer and continued with your suggestion of disabling the Player/Ball layer interaction but i'm finding i'm not getting any physic events between the ball and the players.

    So how can i handle collisions manually if i've disabled the ball/Player layer ?
     
  4. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Cast a physics query from the ball script, via Physics.OverlapSphere on the player layer.