Is there a reason you particularly need the material? If you want to know which side of a cube is being hit, you can get that by comparing the impact normal with the orientation of the cube by getting the dot product of the impact normal with the cube’s current axes – if the dot product is 1 (or very close), that is the direction of the face that was hit.
Hey so I have a 6 sided mesh/cube each face has a different material.
I use this blueprint below. To get my cube (class = world
) and I would like to know what side My cursor is hitting.
Seeing as my cube has 6 sides with each a different material if I could get the material of the face im hitting, then I could get the side.
However I cannot think of a way to get the surface/material/face of the cube.
So back to my question.
How do I get the face of my mesh my cursor hits?
EDIT: I did try face index
in Break Hit Result, it always equals to -1
so I don’t know how to change this.
no I do not need the material. Tho getting the material would make it easier to find the face.
I am not familiar with dot product
I’ve only used UR for a couple months, could you explain how
to get the
dot product of the impact normal and the cube’s current axes
Unless you mean cube’s rotation as the cubes current axes, the cube is never rotated. player rotates the cube.
I mean the cube’s rotation relative to world space – if the player causes the cube actor to rotate, then the cube actor has a rotation relative to world space. It may be simplest to use “Unrotate Vector” to transform the “Impact Normal” vector into world space, then do the dot product with constant values corresponding to the x (1, 0, 0), y (0, 1, 0), and z (0, 0, 1) axes. See the attached
partial example. In the example, the node labeled “X” will be +1 if the face that was hit is in the direction of the cube’s local positive X axis, -1 if it is in the direction of the negative X axis, or 0 if it is in the direction of either the Y or Z axis. The node labeled “Y” will be +1 if +Y, -1 if -Y, or 0 if X or Z, and the node labeled “Z” will be +1 if +Z, -1 if -Z, or 0 if X or Y. Note that the above values may be slightly off due to floating point math, so you would want to check to see if it is “close enough” to 1, or -1, or 0, rather than exactly equal. There is a BP node that will do this called “Nearly Equal.”
If you are going to try to do anything in a 3D game, it will help you a lot to learn some vector math (in fact, I’d say you won’t get far at all and won’t have any fun if you don’t have at least a rudimentary understanding of how vectors work and what the dot product and cross product do). The Khan Academy has some lectures on vectors that seemed quite good.
Hope that helps.
Ah ok. I can understand what you mean,
I do understand how vectors work. I just don’t know a lot about the math that vectors are used for.
For example I can draw a cube and tell you the vector position of all 8 corners Just by knowing the middle vector. But I couldn’t tell you what math is used it in.
I will look at Khan Academy for the videos/lectures you talked about.
And forgive me but I didn’t mean “the player rotates the cube” as in they move it, I meant “the players, rotate around the cube”.
I will let you know if this works as soon as I get on UE
Oh, OK. If the cube is aligned with the world axes, then you don’t need the unrotate, obviously.
If you use normalized vectors, the dot product basically gives you the length of the projection of one vector onto another (actually it’s the cosine of the angle between the vectors). It is calculated as x1x2 + y1y2 + z1*z2.
Thank you
I got it to work using this.
I was testing around using Impact Normal
and dot product and found a solution
I tried this, it returned only 1 material’s name when I used get material from collision face index no matter the side,
and then I used get material
and it returned nothing…
Dont worry i got a solution from the guy above.
Cool, glad you got it working.
@Omar Vector this is not correct. What you show in that screenshot is attempting to retrieve a material using the hit result face index. These are totally different things . Face index will be a value in the hundreds or thousands, corresponding to a single index from the array of ALL faces on the mesh that was hit. GetMaterial() returns a value from the Materials array which is going to be a handful of indices corresponding to the material IDs of that mesh.
Using one to retrieve the other is almost guaranteed to be out of bounds.
It won’t crash, cuz it’s blueprint. But it also won’t work
You are alright, but my mistake only in using wrong node which is GetMaterial, instead I should used GetMaterialFromCollisionFaceIndex