# OnCollisionEnter only triggering if colliding object starts inside collider

Despite the absurdly high number of "OnCollisionEnter not working" threads around the internet, no one else seems to have had this specific problem.

To start off with, I have a spherical "shield" object around my ship, which has a shader designed to give off impact effects when hit by an object. To trigger the shader impact effect, you need to give it the position from which do the effect. So, the easiest way to do this is to give the shield a Collider and, whenever OnCollisionEnter is called, it sends the contact.point details to the shader. That's not the difficult part. The part that isn't working is that OnCollisionEnter is not being called when the laser bolt fired at the shield actually collides with the shield.

Both the shield and the laser bolt have Sphere colliders, both are not triggers. Only the shield has a rigidbody, which is not kinematic.

void OnCollisionEnter (Collision collision) {
Debug.Log (Time.time);
if (collision.transform.tag == "Impact") {
Debug.Log ("go");
}
}
}


That script is attached to the shield object. Not only is "go" never being logged, but neither is the Time, so OnCollisionEnter is not being called.

The odd thing about this scenario is that, OnCollisionEnter will be called by objects that begin inside the shield's collider - so if I start the laser bolt inside the shield, then the function gets called as usual. But when I start the laser outside the shield and Translate it into the shield, nothing happens. For the life of me, I can not work out what's going wrong with it.

• Usually a moving object like a laser bolt would have a Rigidbody attached. Have you tried adding one? Depending on the speed of the bolt there might also be tunnelling occurring, which you can try to address by enlarging the colliders, tuning the physics timestep, or enabling continuous dynamic collisions. Any luck in any of those directions? – DMGregory Jan 9 '17 at 4:27
• For now, for the sake of working out this issue, I've made the lasers travel at 0.25 units per Update frame, which immensely slow. But I did add a rigid body to the laser bolt and now, yes, it does call. What would've been causing it to not work when there was only 1 rigidbody? – DJpotato Jan 9 '17 at 5:40
• > But when I start the laser outside the shield and Translate it into the shield . Why do you translate it's position instead of using Force or Velocity? – Aditya Yadav Jan 9 '17 at 10:02
• A snapshot of your object covered with shield with inspector values will be helpful – Hamza Hasan Jan 9 '17 at 10:08
• When a laser bolt is instantiated, it gets rotated so that it will fire in the correct direction, and then the laser has a script that translates it however much I want every frame. They will only ever go in a straight line so I figured there was no need to bring the physics engine into it. Would there be the specific advantages of using the physics system on a laser bolt? – DJpotato Jan 9 '17 at 10:14