Hello, I’m having an issue with my raycasts only detecting a meshes origin point. I have a wall to test a ledge grab system I’m messing with and everything seemed to be working normally, but when trying to grab a ledge that I made longer(using probuilder for prototype) the ledge isn’t detected at all unless I try at the origin point of the mesh, which is lower than the actual mesh itself.
I added a full picture of the wall for context, but the issue is with the long yellow test ledge I have. I am only able to grab it at the first line down from the actual mesh, even though my colliders look like they all match the mesh. I could very will be missing something obvious but when I looked into the issue, I couldn’t find anything.
Here is my code for detecting a ledge:
ledgeDetected = Physics.SphereCast(transform.position, sphereCastRadius, playerObj.forward, out ledgeHit, detectionLength, ledge);
When using the cast functions you need to make sure that the cast doesn’t begin already inside the mesh or the cast won’t detect anything. Try adjusting the cast start position so that it starts further away from the wall, or reduce the sphere cast radius.
As I said in the post, it works but only when snapping to the origin point of the mesh. The raycast starts inside the player character and reaching out to the space in front of the player to detect if the player is looking at a ledge. It detects every ledge and will snap to them, but only to their origin point and not the mesh colliders themselves.
Well that is definitely something that was ignored with the project I’m learning with lol. Made some other issues but that at least put me in the right direction toward getting this fixed. The person I’m learning from was using ledgeHit.transform.position, which now that I know about .point, makes so much sense why the issue I had was occuring. Thank you so much, I’m really new to raycasts so that was a bigger help than you know!