I’m making a platformer, and I would like to add interesting interactions with enemies and walls. I’m currently working on wall running, and started attempting raycasts to see if I’m interacting with a wall to run on or not. My raycast just won’t interact with the wall, though. And I’ve kind of hit a brick wall with this…unlike my raycasts…
I figured out a new test I can try, and it turns out I have the opposite problem. It’s always hitting the tilemap. I guess because I’m inside it. So I need to figure out how to trigger the raycast only when it hits the solid part of it…
I found my issue: right = Physics2D.Raycast(transform.position, (Vector2.right)/2);
I was under the assumption that the second argument was the line that would be tested for, but it’s the angle at which the line exits the player object. So my raycast was going forever.
There’s a distance parameter right afterward that I needed to add, so the fixed code is:
right = Physics2D.Raycast(transform.position, (Vector2.right), 0.5f);
I normally set two empty game objects up, a start point and end point. This way I can assure that the raycast isn’t going off into infinite world space. I also feel that this gives me more control as well.