# How can I "tilt" my grounded raycast?

I'm working on a 3D game with a spherical collider for the player.

My ground check looks like this, where I'm currently hardcoding Vector3.down as the direction:

Physics.Raycast(position, Vector3.down, out hit, FLOOR_RAYCAST_DISTANCE, PLAYER_GROUND_COLLISION_MASK)

This works for a majority of cases (as does toying with the value of FLOOR_RAYCAST_DISTANCE), but breaks down depending on the speed of the character & the intensity of the slope.

My approach is to tilt the raycast direction dynamically based on the velocity of the player, but all my math so far has fallen apart and hasn't worked, as I'm pretty weak with vector rotations. Can anyone help me figure this out?

See some examples here - in all three scenarios, the collider should be grounded, but it isn't on the slopes.

• Have you considered using a spherecast, so you can detect places where the "shoulder" of the sphere touches the ground, rather than just the bottom tip? Jul 5 at 23:54
• @DMGregory that seems like a good possible workaround, but I wasn't sure of the performance tradeoffs. The game isn't particularly demanding, but a ray seemed a lot less expensive
– lase
Jul 6 at 0:56
• First rule of performance: whenever you say "I'm not sure", measure it. Do not trust your gut about what "seems" expensive - seeming does not ship games. The last time I measured this, a spherecast was only 30-50% more expensive than a single ray cast. So if you needed to do one raycast to determine the angle to tilt, then a second raycast in that tilted direction, you're already paying more than for a single spherecast that solves it in one fell swoop. Jul 6 at 2:19
• @DMGregory right, you should use Spherecast Jul 7 at 14:33
• Thanks for the input @DMGregory - if you want to type it up as an answer I can accept it, or I can answer myself in detail once implemented
– lase
Jul 11 at 13:47