Zero out Y axis relative to the player.

I have two objects in the scene, a cube (Rotates around the player) and a cylinder (The player who can move on spheres). I am casting a ray from the cubes transform.position to the players transform.position. And that raycasts information, I am casting another ray from the players position in the direction of the first raycast after zeroing out the y axis (as mentioned by @Kurt-Dekker in the post - Help Wanted - Raycast reflection opposite. - Unity Forum )

This works as intended on flat surfaces perfectly, but when the player is walking around the sphere, the second raycast is always set on the Y axis in the world space instead of the characters Y axis (Black line in the images) Is there a way around this, where the characters rotation is taken into account?



Vector3 newDirection = Vector3.ProjectOnPlane(vectorToProject, playerTransform.up);

Wow this works great!!! Thanks @TimmyTheTerrible
Thanks to your too @Kurt-Dekker , you’ve been amazing.