- Home /
Fast moving object passing through other objects.
Hello guys, I am pretty new to unity3d and making a small example. actually i have a cube which moves with my arrow keys. now i have walls on the road i want my object to hit the wall but it pass through the wall.
i also have used this code but no result.
http://www.unifycommunity.com/wiki/index.php?title=DontGoThroughThings
any help will be appreciative. thanks
Do you have colliders on your "walls"? What kind? Box? $$anonymous$$esh? Do you have a collider on your floor/road? Or does your cube float in space and is moved by your scripts alone? Do you have a collider on your cube?
i just have box collider on my floor and wall and also $$anonymous$$esh renderer is attached to them.
i can move my cube from arrow keys with transform.translate.
maybe its because your box is moving too fast/is too small to be detected by the colliders?
rigidbody.AddForce(tranform.right * speed) is not working. my object aint moving with force.
Answer by superpig · Apr 26, 2011 at 09:20 AM
Your cube needs to have a non-kinematic rigidbody attached to it, and you have to move it by applying forces, rather than by setting transform.position.
If you've got the rigidbody, make sure that 'Collision Detection' is set to 'Continuous.'
right but if i uncheck the kinematic box in rigidbody my cube hides / blew away in space.
and yep i am using transform.translate not transform.position.
transform.translate isn't applying forces, it's just setting the transform. You need to use Rigidbody.AddForce() and similar.
thanks god!!!!!! set 'Collision Detection' to 'Continuous.' ~~~~~problem perfectly solved (>3<)
Answer by Cyb3rManiak · Apr 26, 2011 at 01:03 PM
First - unless you have a particular reason to script this whole thing from scratch the way you did - I would advice you to attempt using the CharacterController.
About your situation - if you DON'T have a collider on your moving box - that's your problem. A collision between two objects must involve at least two colliders (one on each object), and a rigidbody on at least one of the objects. You have colliders on your walls - so all you need is a collider on your box.
BTW - Double check that the box even collides with the floor. If the rigidbody you have is kinematic - it means it isn't effected by gravity. Do you simulate it? Do you have some line in your script that attempts to move the cube down each frame? I would first check to see if it collides with the floor.
About the rigidbody and forces discussion... To make things clear - if your rigidbody IS kinematic - the physics engine doesn't effect it. You use straight-forward scripting to move your cube (Transform.Translate, Transform.position etc.). If your rigidbody IS NOT kinematic, it means it can move from forces from the physics engine, and then you should use AddForce/Torque etc to move it. Which way you go is entirely your choice.
Answer by AngryOldMan · Apr 26, 2011 at 11:39 AM
Have you tried increasing your skin width? how big (scale wise) is your cube? how big is your level, what speed is the rigidbody moving at?
Answer by brentrkendall · Feb 26, 2017 at 01:27 AM
I had objects passing through other objects even after considering all the usual culprits: rigidbody, colliders, isKinematic, continuous collision detection, etc. In my case, I eventually discovered the cause of the problems was the MATERIAL on the object getting passed-through. It had a material with a partial transparency (alpha value), and at those certain transparent spots (which weren't visible to the naked eye), my projectile would pass through. An easy way to tell if your problem is related to the MATERIAL on an object is to set the material of the pass-through object to just a based default plain material, and see if the pass-through no longer occurs. If so, then you'll need to modify the transparency/alpha values on the problem material before reapplying it.
Answer by ccjbn · Apr 12, 2019 at 03:12 PM
I had to set my object to Continuous Dynamic, because my object still passed through. Of course you can also limit the speed of your object. It seems to happen at higher speeds. I can only assume that that is because the object position is skipping chunks of screen to appear like it is faster and it skips over the area where the collision is detected.