- Home /
Raycast On Rigidbody
Allow me to ask a simple question.
For successful trigger the raycast function, the gameObect must have a collider?
Because i can not detect the gameObject using raycast while the gameObject only have rigidbody and does not have any type of collider.
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray,out hit, 100.0F))
{
Debug.Log("Hited Objects:"+hit.collider.gameObject.name);
}
My code is using mouse cursor to detect the gameObject.
Is that have anyway to detect the gameObject using mouse while the gameObject only have rigidbody attached and without any collider.
Answer by FLASHDENMARK · Jul 19, 2011 at 08:21 AM
var hit : RaycastHit;
function Update (){
if(Physics.Raycast(transform.position, transform.forward, hit, 25)){
if(hit.rigidbody){
print("A rigidbody is hit. Let us celebrate. Shall we?");
}
}
}
I believe that is how it is done.
i have update my question, i think the solution above is working if my gameObject have collider.
How about while the gameObject only have rigidbody, we still can detect it?
Your answer
Follow this Question
Related Questions
RigidBodies vs CapsuleCasts 0 Answers
0 Understanding of raycast2D commands 2 Answers
Drag Rigid Bodies First Person Controller.js 0 Answers
Picking up rigidbody objects 2 Answers
How to Add a Decal When a Rigidbody Collides with a Surface? 1 Answer