- Home /
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
If the separate pieces were not grouped, you have to add a mesh collider to all of the pieces. I had the same problem when I was making a desk, but I fixed it and now I'm fine.
Answer by Alec-Slayden · May 04, 2011 at 04:47 AM
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.
Is there a way to have isTrigger checked and still have the physical solidness of an object? @Alec Slayden
there is a function called OnCollisionEnter(){}
Answer by wmadwand · Nov 04, 2014 at 05:24 PM
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".
Answer by GaryTheBard · Feb 06, 2017 at 01:05 PM
@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;
Answer by umair_hassan · Mar 22, 2017 at 11:10 AM
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:
float speed = 5;
void Update(){
transform.position = transform.forward 20 speed;
}
void OnCollisionEnter(Collision hurdle)
{
if(hurdle.name == hurdle)
{
speed = 0; // this way your chahracter will not move if it collides to hurdle
}
}
Answer by darknubis365 · Feb 01, 2018 at 02:42 AM
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
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Sprint Error script? 2 Answers
how to make a character walk with touch in android 0 Answers
Making Character Stand? 1 Answer
How to make a character stop going through the terrain? 0 Answers