Home Technical Talk

Given two world space coordinates (A & B), find offset of B from A in local space

Hey guys, I'm working on a first person red dot sight and I want this laser effect to really pop. I'm working in Unreal, and I have a camera and a weapon sight attached to it. The camera is free to move about the world and look in any orientation with the weapon following it. I've got some subtle movement of the weapon in relation to the camera as a weapon sway, especially noticeable after the player does some sprinting or when he holds his breath (in that the motion stops). I want to pan a texture across my laser reticle to create a speckling effect to help my sight feel alive and less like a texture slapped on a plane. But the catch is I want the texture to pan its UV coordinates in relation to the weapon moving against the camera in Y and Z local space, not from either object moving around in world space. This way, when the player sprints and scopes, the speckling effect is faster and when he holds his breath, it stops and is not distracting from precision shooting.

I don't have code support to pull down offsets as I would like to make this material self-sufficient to work on all our red dot and reflex sights. So I'm working in the material editor for this.

Unreal gives me access to the object world position, the object orientation (though I don't know how that information comes in), and camera world position. I don't need the camera orientation, as I know that both the camera and weapon always look down +X.

I can get the weapon offset from the camera by simply subtracting one from the other, but those values are still in world space. Looking around the world will change which axis of the offset needs to get piped into what U or V input.

How can I get the offset of the weapon from the camera in camera world space, so I can run them into my UV coordinates of my speckled texture?

Ben

Replies

Sign In or Register to comment.