Hi My parent gameobject has two child box1 and box2 ,I am casting ray from box1 to box2.
and rotating the parent object .
As the parent object is rotated the child object also get rotated and but ray cast is not getting Updated
void Update()
{
RaycastHit2D hit;
hit= Physics2D.Raycast(box1.transform.position,box2.transform.position);
if(hit.collider != null)
Debug.Log("hit.collider.name");
}
Now I am rotating the parent game object with raycast is not getting updated
I even tried taking localposition
Any help
Hi everyone I solved it using the following code
void Update ()
{
hit = Physics2D.Raycast (new Vector2(box1.transform.position.x,box1.transform.position.y),
box1.transform.TransformDirection(rayvec),.5f);
hit1=Physics2D.Raycast(new Vector2(box2.transform.position.x,box2.transform.position.y),
box2.transform.TransformDirection(rayvec),1f);
if (hit.collider != null)
{
ray1= true;
//print (hit.collider.name);
Debug.DrawRay (new Vector2(box1.transform.position.x,box1.transform.position.y),
box1.transform.TransformDirection(rayvec),Color.blue);
}
else
{
ray1 = false;
}
if (hit1.collider != null)
{
ray2= true;
//print (hit1.collider.name);
Debug.DrawRay (new Vector2(box2.transform.position.x,box1.transform.position.y),
box2.transform.TransformDirection(rayvec),Color.white);
}
else
{
ray2= false;
}
}