- Home /
 
               Question by 
               TheFeaturedEpic · Jan 25, 2016 at 12:25 AM · 
                2draycast2d-platformerraycasthit2d  
              
 
              Error with 2D Raycast
Hi,
I am trying to develop a shooting mechanism for a 2d platformer and have got to the point of raycasts. This is the code that I am currently using for the raycast:
 void Shoot() {
         RaycastHit2D hit = Physics2D.Raycast(new Vector2(firePoint.position.x, firePoint.position.y), new Vector2(Input.mousePosition.x, Input.mousePosition.y), range, notToHit);
         Debug.DrawLine(new Vector2(firePoint.position.x, firePoint.position.y), new Vector2(Input.mousePosition.x, Input.mousePosition.y) * 200);
 }
Range is a float and notToHit is a LayerMask. However, with this code, the Raycast goes off at random angles (see images, the yellow highlighted part is where my cursor was, the white line is the raycast).
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                