- Home /
Raycast Physics2D not working as expected
I have a custom 2D gameobject that I am raycasting down onto the ground to check ground collision (and eventually want to do horizontal raycasts to other game objects) and this is my code:
    Vector2 offset = GetComponent<BoxCollider2D> ().size * 0.5f; 
 //offsets so I don't hit my own BoxCollider2d
 
     bool hit = Physics2D.Raycast ((Vector2)transform.position + offset, -Vector2.right, 1);
 //ray cast down from my objects position
     Debug.Log (hit);
 //always outputs false
Just wondering how I could improve this so my desired behavior is performed.
               Comment
              
 
               
              Answer by robertbu · Mar 18, 2014 at 04:08 AM
One issue is that you are using -Vector2.right which casts left in world space. Replace with Vector3.down. This is world down.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                