Search Unity

Make CharacterController unpushable?

Discussion in 'Physics' started by my_little_kafka, Oct 14, 2017.

  1. my_little_kafka

    my_little_kafka

    Joined:
    Feb 6, 2014
    Posts:
    87
    I'm working on a first person game. Player controls a character that is driven by a standart Unity CharacterController component and my custom controller script that moves the player character with CharacterController.Move() function.
    There was a problem with collisions with Character Controller and Navmeshagent driven characters - for example, if I spawn a lot of these characters, they will walk towards the player character and eventually they will push PC out of the level (through mesh collider, box collider - doesn't matter), which is the behaviour I don't want in my game (even though I'm not planning having that much enemies in a single battle).
    Also there was another problem - Player Character could push enemies, which I wanted to control with special functions, not by just moving at them.
    I solved these problems just by randomly tinkering with variables - and I found that enemy character with navmeshagent must also have a CharacterController attached, which will act as a collider (it will won't with Capsule Collider, enemies will still push Player Character), and it must have a bigger radius than Navmeshagent. This way Player Character won't be able to push enemies, and enemies won't be able to push PlayerCharacter - even if they're Root Motion driven - this is the behaviour that I want.

    But now I have another problem - this way I'm forced to make enemies with a standart radius collider, which is good for biped and small creatures, but is not fitting for enemies with irregular shape, for example, long enemies like snakes - if I make another collider so the Player Character couldn't walk through enemy's tail, the same tail's collider can potentially push Player Character out of bounds of the level.

    I'd like to make Player Character with CharacterController component unpushable - and I want to control what to do with Player Character if the enemy collides with them - is this even possible with CharacterController (I'm not sure I will be able to write my own controller with Rigidbody, for example - a lot of work and I'm not a very good technical programmer for this task)