hi, I need to move object and detect collision. I have 2 wals and 1 cube and I want to move this cube left or right and when it touchs the walls it must be stopped. I did this by cahracter controller but if I speed up, when it touchs the walls it is sliding. I cant do this with rigid body because when it is rigid body it isn’t stopping when touching walls. And if I do moving simple with gameobject it cannot detect collision. please give me example how can I fix this?
if you don’t want to use rigid body then you would have to implement your own collision detection algorithm which is not easy to do, unless you are only dealing with few limited cases. For example if your box doesn’t rotate and your walls and box have the same orientation then you can simply do something like if(Mathf.Abs(box.position.x - wall.position.x)<w) then you have a collision.
For the general case though you probably want to use onCollision functions that come with unity and rigid body.
Hi, not quite sure what your trying to achieve but I suggest you look into the OnTriggerEnter function which is similar to OnCollisionEnter but uses Kinematic rigidbodys.
Take a look at this section:
http://unity3d.com/support/documentation/Manual/Physics.html
What you could do is detect the OnTriggerEnter event then manually position your cube.