CharacterController and Instantiating an object with collider
I am working on a 2D game, and I have created a character than can throw stones. The way I decided to implement this, is to Instantiate a little rock with a rigidbody added to it and a collider. I will then add force to the rigidbody when it is fired.
The problem occurs when I spawn the stone, as it will push the character back (as their colliders hit). I have tried to solve this with all sorts of different methods, the only one working being moving the stone OUT of the Character Controller's collider. This is not satisfying as the stone is too far away from the character now.
I have tried with layers, OnCollisionEnter and the CharacterControllerCollider, all of them failed as the item will push him as it spawns, which means even when I get to ignore their collision, it will already have pushed him.
Does anyone have a tip to how to solve this? Eventually a really smart way to manage what collides with what, as it will benefit if I can turn on collision between the player and the stone again afterwards.
Answer by birdinforest · Oct 19, 2016 at 11:43 PM
@Aveneon Hi. Have you worked out this problem? I think you could instantiate a inactivated prefab(a rock), ignore collision between the rock and character, then activated it. Use coroutine to cancel collision ignore later.
Just realize that set collider on rock to be trigger before instantiation is a better solution.
Just a suggestion. I haven't tested that.