- Home /
I can walk through an object with a mesh collider?
So I created this small model for a room. It's a box with its normals inverted so I can see the walls on the inside. It's also one sided so I can see through it from the outside. In Unity I check the Generate Colliders option and add into the game world. But when I move my character, from the inside, to the wall. instead of bumping into it he walks straight through, why is this? and how do I fix it?
My character also has a collider on it.
$$anonymous$$ight have nearly solved this myself sorry :( I think it's something to do with my movement.
transform.Translate(Vector3.forward * Input.GetAxis("Vertical") * moveSpeed * Time.deltaTime);
is your movement being called in Update or FixedUpdate? have you got a rigidbody on your object? Using forces for movement may work better!
Assu$$anonymous$$g the object inside the box has a Rigidbody, use Rigidbody.$$anonymous$$ovePosition() rather than Transform.Translate()...or use Rigidbody.AddForce() or set Rigidbody.velocity.
Answer by DrakeDiablo · Aug 29, 2014 at 06:05 PM
Because you are inside the collider, since your room is a box, that means that mesh collider is going to create a big box, and it will only detect collisions on the outside. If you want to make a room, put together like 6 cubes, each being for a wall and ceiling. Hope this helps! :D
Actually, if the normals are pointing inward as indicated, then the inside surface should be the one he is colliding with.
Answer by Systemfre1 · Aug 29, 2014 at 07:29 PM
Thanks, for your answers. But I found the problem and fixed it.
Because my movement was transform.Transalte it was forcing its way through anything, because it techincally wasn't moving. It was acting more like a teleport.
I replaced it with
if (cc.isGrounded) {
moveDirection = new Vector3 (Input.GetAxis ("Horizontal"), 0, Input.GetAxis ("Vertical"));
moveDirection = transform.TransformDirection (moveDirection);
moveDirection *= moveSpeed;
}
moveDirection.y -= gravity * Time.deltaTime;
cc.Move(moveDirection * Time.deltaTime);
My only problem now is that I don't have the customization that I wanted for sprinting only when moving forward and stuff like that, but it doesn't matter to much to me.
Hope this helps if someone encounters this problem in the future.
Your answer
Follow this Question
Related Questions
Adding colliders to human imported fbx - Newbie 1 Answer
RaycastHit2D hits "itself" 3 Answers
How can I do drilling using mesh colliders 0 Answers
boost and hit the edge of a collider and you go backwards 0 Answers
Colliders on this spider 1 Answer