checking for collision before displaying.

I want to check if an object I am instantiating will collide with anything on creation. I can use OnCollisionStay or similar function to check in the next frame if is is colliding with something but I would like to check before it appears on screen–it looks ugly flashing on screen then going away. Preferably I would like to check in the line immediately afer instantiating the object.

Any Suggestions?

cheers,
Grant

Edit: typos edited.

You could turn the renderer off when instantiating, and then turn it on the next physics frame.

–Eric

Nice that would get rid of visual blip. “physics frame” does that mean fixed update call? I though (probably mistakenly) that frame in the documentation meant video frame. How do I find out if there has been a collision in the FixedUpdate frame? I though MonoBehaviour.OnCollision* functions were called on video frames. I see the Collider.OnCollision* and Rigidbody.OnCollision* functions also but they seem to be messages sent to MonoBehaviour.

The objects I am instatiating are on a hingeJoin. I might be able to do something checking for high angularVelocity in fixedUpdate.

I also realized that when I instantiate inside another object I am bouncing off it causing the whole hierarchy to jiggle and shake. So idealy I would like to check if there will be a collision and before it starts causing physics to push everything around.

I may just send 14 rays(faces and corners of a cube) out before instantiating and check distance to collisions, Or a combination of the above.

Cheers,
Grant

There’s also Physics.CheckSphere, will that work in your case? You could set the radius of the sphere to something that matches the bounds of your object. Then instantiate if CheckSphere returns false. You could also check multiple positions in one frame until you find a valid one.

/P

Thanks that is what I needed. CheckSphere, CheckCapsule in physics will almost do what I want. They won’t tell me what I hit, but LineCast will. I keep looking at collider and for some reason had a mental block about looking in Physics class functions.

cheers,
Grant