- Home /
Make transparent 3d object with collision detection
I am newbie in unity3d, I just want to make a square area which will should be transparent and when a object enter into that square area or touch that area then I should let know that some object enter or touch area. Kindly let me know or suggest me how can i do this task. This will be great for me. Thanks in advance.
Answer by Remaille · Feb 01, 2013 at 08:11 AM
What you want is a GameObject with a collider marked as "trigger" and a script reacting to the OnTriggerEnter event.
Here's how you can do it :
Create an empty GameObject
Add the component Physics/Box Collider to the object (other shapes are ok too)
Tick the option "Is Trigger" in the box collider properties
Create a script for this gameObject
Add the functions OnTriggerEnter, OnTriggerStay, OnTriggerExit to your script. And do whatever you want to happen in them.
documentation for OnTriggerEnter documentation for OnTriggerStay documentation for OnTriggerExit
Answer by archaismic · Feb 01, 2013 at 08:13 AM
make a cube or plane or whatever shape via
GameObject->Create Other->Cube
put it where you want it and go into the inspector and click "Is Trigger"... this will make the box so you can walk through it
then remove the mesh renderer component and it will be invisible
you can then refer to the name of your Cube in a script to trigger events
then click the
Answer by Bluntweapon · Feb 01, 2013 at 07:33 AM
Make a cube, delete the Mesh Renderer, add a collider and make it a trigger.
Now you can attach a script onto the object with
void OnTriggerEnter() {
AlertOtherObject()
}
or if you use UnityScript
function OnTriggerEnter() {
AlertOtherObject();
}
Check this page for more info
Thanks and got it, and second object which is going to enter in that area should be rigidbody or just add collider on it, because when I was adding rigidbody on it, it repells on touch and start moving?
Ok there were like 3 things wrong with my original anwser, my apologies. You really should be using
void OnTriggerEnter(){
}
ins$$anonymous$$d.
Second, yes the second object should have a Rigidbody (or CharacterController) attached.
If that's going to be a problem, however...well I guess you can always use a kinematic Rigidbody.