Each face of a body has armor thickness assigned to it. When a projectile hits a face, I’ll calculate penetration based on impact angle and armor thickness.
I came up with two approaches, but I couldn’t complete any of them.
Hit Result - Face Index. The idea here is to have a TMap<int32, float> where each face has thickness assigned to it. The problem is map initialization. I’ll probably need to write custom FBX parser to get list of triangles and color assigned to them. Is there an easier way to assign color/float to a face?
The problem here is that I couldn’t find how to get pixel color using these UVs. Also it looks like a costly operation if it has to be enabled on project level.
(I’m doing extra line trace from slightly above collision point to slightly below it, because original hit result doesn’t return face index or UVs)
Ideally you make a proper UV, a texture that represents the thickness, and read the value of the texture out, then scale it for the value it stands for. This because in texture form it reads as 0 to 1 range.
This isn’t at all dissimilar from the cloth painting process, but you really want to have a single texture in charge of it for ease of use, and because vertex paint isn’t going to cover it.
If you bake the texture to represent a distance in cm you just read the texture value on hit, multiply it by 10 - which for some tanks should likely be more than enough thickness, and make whatever other determinations you want based on it.
A little note - the hit returns your UV results X and Y.
The texture you already have.
Reading a pixel from the texture? - I suggest you create that in c++ as it’s very simple and the engine doesn’t really do it via blueprint without hoops you do not need.
Well, at least older engines, maybe they introduced something in the newer versions I’m not aware of. Either way. You can Google for direct c++ code to read a pixel in OpenGL.
There are also some code based unreal examples which you can implement straight up and wrap into your own c++ function making the process preferable to using the native BP stuff that overloads things and does a lot you do not need to do for this to work.