Vector direction after collision

I’m trying to make a “hook” with some given direction and length.

Until that, okay, i get the direction from my mouse click position:

Vector3 direction = Camera.main.ScreenToWorldPoint(Input.mousePosition);

And I need to move the “hook” head from my position to the “end” position:

Vector3 end = direction * length;

Now, i need to add some functionality to it, which is, when the “hook” head collides with a wall (and it still has some length available), i get the resulting direction of that collision (that’s what i need), multiply it to the remaining length and i have my updated end point.

I tried to do that with the Vector3.Cross(…), passing as parameters the Vector3.up and the hook current direction.

I’m not getting the result that i need, here are some examples of the direction i want:

Thanks in advance.

Actually all you need to calculate the reflected vector is the surface normal vector (which you get from a raycast) and the Vector3.Reflect method.

ps: ScreenToWorldPoint takes the distance from the camera as z component. If you pass a Vector2 / mouse position the z value will default to 0. If you use a perspective camera that means it will always return the camera’s position since at 0 distance all points meet at the same point. See the example on the documentation page. They use the cameras’ near plane value. Also keep in mind that you will get a position, not a direction.

If you actually plan to do a raycast along that direction you might want to use ScreenPointToRay instead. It returns a ray that has it’s origin at the camera position and a direction that points where you had your mouse position.