How to make a solid object so that character cannot walk through

Hi,

I am new to Unity. I am having a problem with a solid object. I wonder how to make a solid object so that the character cannot walk through it. I even try Mesh Colider but it's seem not working, my character still walk through it.

Thanks

Hi JNguyen

Your solid object and your character must both have colliders, but the types of colliders must be a certain mixture. For example, two cube colliders will ignore each other unless one has a rigidbody.

There are very specific ways colliders will work together. At the bottom of each page in the manual dealing with a collider, there is a collision matrix to help you.

Also make sure you do not have "is Trigger" selected for your colliders. This is a setting that is for trigger detection only, without any physical collision.

Primarily your Character must be solid. For that do this: select your Character in the Hierarchy → go to the Inspector → select and expand Capsule Collider → uncheck “Is Trigger”.

@BluEye - Yes you can technically have IsTrigger checked and still have the physical solidness of an object. I needed to solve this same issue, where I wanted the graphic of a platform to change when the player collided with it. Unfortunately, I was able to get the graphic to change, but then the character would just pass through the new platform. The way I solved it was setting IsTrigger to false within the OnTriggerEnter. If you need the trigger to occur every time that the player collides, you can set IsTrigger back to true in the OnTriggerExit portion.

        this.gameObject.GetComponent<BoxCollider2D>().isTrigger = false;

90439-ss.png
If you are transforming your character, no collider will stop him from passing through unless you check in OnCollisionEnter() function and stop him if he collides to the hurdle.

e.g:

  1. float speed = 5;
  2. void Update(){
  3. transform.position =
    transform.forward * 20 * speed;
  4. }
  5. void OnCollisionEnter(Collision
    hurdle)
  6. {
  7. if(hurdle.name == hurdle)
  8. {
  9. speed = 0; // this way your
    chahracter will not move if it
    collides to hurdle
  10. }
  11. }

I am having some trouble with this right now as well trying to make NPC vendor’s when walking up to purchase an item pressing W and walking forward i can push my NPC vendor out of place,its driving me crazy lol