- Home /
[help]RayCast check [SOLVED]
Solved - I found out that I had the Layermask set up wrong i had it set to ignore everything but the player i just switched it around and now it is working thanks for the help.
I have this java-script which shoots a raycast from the camera in the direction it faces. The raycast checks to hit any rigid-body then extra work which is pointless to this question. The camera is inside the default First Person Controller. Scripts is functioning until I try to raycast downward. The raycast debug line that is drawn shows that the raycast is hitting the player collider. I know how to code C++ pretty well so don't try to answer this like I'm a complete idiot who thinks I can jump into the action.
How would I be able to check the tag of the rigidbody I hit in this script.
Physics.Raycast(transform.position, transform.forward, hit, RayDistance, layerMask.value);
Debug.DrawLine (transform.position, hit.point, Color.green);
if(RaycastHit){
if(hit.rigidbody){ //I want to check if the rigid body is NOT the player.
Here's where the crap happens.
}
}
Answer by robertbu · Dec 25, 2013 at 02:15 AM
A raycast (3D version) returns a boolean indication whether it hit something. You can structure the cast and the check to make sure it's not the player this way:
if (Physics.Raycast(transform.position, transform.forward, hit, RayDistance, layerMask.value)) {
if(hit.collider.name != "Player") {
// Do stuff here
}
}
You can check the tag rather than the name if you have your player tagged:
if (hit.collider.tag != "Player") {
}
Answer by jzapper · Dec 25, 2013 at 08:41 PM
[Edit] I found out that the raycast only grabs rigidbodies that are in sight and stuff. When I look down at the object and try to pick it up the character controller collider cylinder gets in the way of the object so it can't pick up the cube or whatever object in its sight so my question is, **
Is there a way to change the collider of the character controller to a different collider such as a mesh where there is a line of nothing down the middle of it? if so how can i do that?