Author Topic: Detecting which brick face has been hit by a raycast  (Read 897 times)

Is there a way to detect which face of a brick has been hit by a raycast? Basically what I'm doing is finding which face has been hit, and finding the centerpoint vector of that face. I know how to get the brick's centerpoint and the vector at which the raycast stopped, but I don't know how I would go about finding which face has been hit. Is it possible, or will I need to use some sort of hackish method?

I'm sure there's no functions for this. you'll have to calculate which side depending on the location of the brick, start ray cast and end of the ray cast.

One of the vectors in the result of a raycast is the normal, which is a vector perpendicular to the face that the raycast hit (don't have Blockland installed but IIRC `normalFromRaycast` is the function to get it, you can also use getWords but I would recommend that utility function). So "0 0 1" would be a face horizontally flat and would have the familiar stud decal on it. You can hence find out the direction the face is facing, but you don't have any statistics about the size of the face, its distance from the centerpoint, etc. so I'm not sure how you would find the centerpoint of the face.

EDIT: You can do it for cuboid bricks, but I assumed you wanted it to work for all bricks.

One of the vectors in the result of a raycast is the normal, which is a vector perpendicular to the face that the raycast hit (don't have Blockland installed but IIRC `normalFromRaycast` is the function to get it, you can also use getWords but I would recommend that utility function). So "0 0 1" would be a face horizontally flat and would have the familiar stud decal on it. You can hence find out the direction the face is facing, but you don't have any statistics about the size of the face, its distance from the centerpoint, etc. so I'm not sure how you would find the centerpoint of the face.

EDIT: You can do it for cuboid bricks, but I assumed you wanted it to work for all bricks.
goddamit