Calculating coordinates using an offset from an entity in 3D space knowing its position and rotation.

152 Views Asked by At

I am working on a game mod for FiveM which allows players to see bullet impacts and their angle of impact, and am trying to implement 'attaching' this evidence to objects which are not static. I have successfully done this for vehicles, but am running into issues with peds as they are not rigid objects. I am attempting to work around this by attaching these impacts to an entity bone (such as an arm or the ped's head) and then calculating the offset from that entity bone and drawing a line between the two to represent the bullet's flight path.

For general impacts against static objects, I simply calculate the vector between the muzzle position and the impact coordinates, normalize that vector to create a pair of coordinates 1 unit apart, and then draw a line between them. I can use the native function in the game mod to get the offset from an entity, and when hitting a vehicle can calculate the offset of the normalized vector and get its offset with that function to draw it, but no function exists to get the offset from an entity bone.

My problem is that I do not understand complex numbers and am struggling to find the math I need to calculate that offset given the rotation and the position of the entity bone. When the bullet hits, I am able to calculate the offset, and get the rotation of the entity bone, so I know I need to compare this against its current rotation, I am just not sure how to translate that to the new coordinate in 3D space.

I looked at quats and this seemed to kind of correspond, but is very much beyond my understanding. It also looks like a rotation matrix might be something I need to do to solve this, but it would be nice if anyone would be able to point me in the right direction or if this is a common thing point me to a solution that already exists.

Example drawing impact evidence on a ped, due to the ped being non-rigid, it only works well when the ped is in roughly the same 'shape' as when it was hit by the bullet.