- Home /
Raycast detects 2/3 of a collider?
The Raycast I am using detects 2/3 of my starting platform. It doesn't detect the right edge. It also doesn't detect my other platform under the same tag. If anyone could help me that would be great took me forever to get the raycast to actually start working and now its acting a bit wonky. The code snipet :
//RayCasting
void FixedUpdate ()
{
float rayDistance = 1f;
Vector2 underPlayer = new Vector2 (transform.position.x, transform.position.y - 1);
//debug raycast
Vector3 debugUnder = new Vector3 (transform.position.x, transform.position.y - 1, transform.position.z);
Debug.DrawLine (transform.position, debugUnder, Color.green);
RaycastHit2D HIT = Physics2D.Raycast (transform.position, underPlayer);
if (HIT) {
if (HIT.collider.tag == "floor") {
grounded = true;
print ("Is grounded");
}
} else {
grounded = false;
print("not grounded");
}
}
EDIT: moved raycasting to update function still doesn't work and here is an image of the scene Also I have the platforms wrapped in a game object it has no colliers but maybe that is the problem??
Have u tried this under Update ins$$anonymous$$d of Fixed update? Usually raycasts are not done in Fixed Update
And u need to be clear in ur question.. What does right edge mean? where is "another platform"
You are right I added an image of the scene and annotated. @RakshithAnand