- Home /
Question about collider (box and .fbx)
Hello! I have a wall (a cube) and a rat that I made using 3dmax (a .fbx), both with a box colider, but whem my rat moves (gameObject.transform.Translate) it crosses the wall.
I would like the rat stops walk when touch the wall.
Answer by syclamoth · Sep 19, 2011 at 04:20 AM
Transform.Translate doesn't care about physics! You need to have a rigidbody component on your rat, because two colliders on their own are assumed to be static, and do not collide with eachother! For the physics engine to detect collisions and push objects out of other colliders, you need to be using a non-kinematic rigidbody.
You should take all of your movement code out of the Update loop, put it into the FixedUpdate loop, and use rigidbody.MovePosition instead of transform.Translate for your motion. This should make your colliders interact with each other!
Answer by Clunk · Sep 19, 2011 at 04:12 AM
Use a raycast collider component on the rat for this. This is not a script, it is part of one to get you started. For more help, look up Unity script reference RaycastHit.
var direction = transform.TransformDirection(Vector3.forward);
var hit : RaycastHit;
if (Physics.Raycast (transform.position, direction, hit, 1))
Your answer
Follow this Question
Related Questions
Internal collisions 1 Answer
Raycasting question 2 Answers
Move Box Collider seperately from gameObject 3 Answers
Tipping a cube over 2 Answers