- Home /
Detect collision from a another object,Detect collision from another script
In my scene i have a object which follows my cursor. When i click with the mouse button, this object gets placed on the ground. But some places, you can't place it because something is in the way, and that is what im trying to detect. The script is attached to the camera, and when i use OnCollisionEnter, it uses the cameras collider, and not the object. Is it possible to make collision detection between two object, from a other object?,
Answer by Kossuranta · Feb 15, 2017 at 12:50 PM
At least I don't know anyway to do that, but you can accomplish wanted effect in multiple ways.
It depends on what you are doing and how it plays out, but I would create empty object that has the script you currently have in camera. This empty object would follow cursor and the object you are placing is child of this empty object. OnCollisionEnter will trigger from child object colliders. When you click to place the object, just detach it from the empty parent object.
One other way to do this would be adding script to the object that follows cursor that has public bool which is set true OnCollisionEnter. When you pick up the object (or whatever happens in your game) you can set the script of that object to variable in the script that your Camera has. Then when you click you can just check if the boolean is true.
Answer by Akash-bhatt · Feb 17, 2017 at 09:12 AM
make sure both object have collider&rigidbody attached and one of them have a OnCollisionEnter method in script attached with it.
Your answer
Follow this Question
Related Questions
onCollisionEnter 1 Answer
Collision detections fails to re-detect an object 1 Answer
WALL collision detection problem... help!!!! 0 Answers
collision detection 4 Answers
Collision Detection 2 Answers