Location of raycaster in relation to hit object

I have an object that will get hit with a ray (user collision box) and I need to determine the location of the origin of the raycast in relation to the object.

Essentially, I am trying to determine if my user is getting hit from behind, in front, or left or right… not sure what the easiest solution to that is?


This was raised recently, but I’ll recap here:
There are two methods you could use.

  • You can use the dot product to get the side relative to the forward before vector of the object, and use the cross product of the up vector with the forward vector to dot product with the ray to get front or back.

  • You can transform the ray to object space and you’ll be able to tell more easily which side and direction is which by ,lcomparing axis values (we are now transforming the source position into an axis aligned position.
    See this example

sides.blend (85.3 KB)

Thanks for the blend… after some trial and error (moving the directions around) managed to get it working just fine, thanks.