Hey all! So I'm trying to set up a really simple grappling hook mechanic. I have a player circle with some anchor squares for right now. All I'm doing is doing the raycast so I can make sure it's actually hitting something, except I'm getting weird behavior on my raycast. I'm storing the raycast hits in a List<RaycastHit2D> and then just printing how many are in the list. Check the attached image for my setup and results. The three lines are just a Debug.DrawLine call set to show the Raycast. If you look in the console I get different amount of hits and I've no idea why. The amount of hits should always be 3 if I'm aiming through the bottom. Here's my raycast code with the Debug code in it. X and Y are player movement input Any ideas what's going on? Code (CSharp): private void Shoot(float x, float y) { Vector2 newVector = new Vector2(x, y); List<RaycastHit2D> raycastHit = new List<RaycastHit2D>(); Physics2D.Raycast(playerPosition, playerPosition + newVector, noFilter.NoFilter(), raycastHit, maxDistance); switch (i) { case (0): Debug.DrawLine(playerPosition, playerPosition + newVector * maxDistance, Color.red, 3f); i++; break; // ... and the two other switch statements for color and resetting i to 0 } foreach (RaycastHit2D hit in raycastHit) { if (hit == circleCollider) // If it's the player, do nothing continue; if (hit.collider.tag == "Anchor") { Debug.Log($"Hit {hit.collider.ToString()}"); } } }
You're using the arguments for Physics2D.Linecast not Physics2D.Raycast . The second argument is the direction as the docs state. Shouldn't this be "hit.collider == circleCollider" ?