I am trying to create an ADS system by moving the primary part of the gun such that the sight attachment is directly in front of the camera.
Here is my set up, where…
C is the camera
G is the gun
S is the sight
S and G are linked and move together
I can only position S by moving G. So here is how I would solve this usually
I find the difference S and C, and then move G by that difference. Then S = C, because adding that difference to G also adds it to S.
I don’t know how to do this with CFrames. Any help would be much appreciated. My effort was this…
local difference = s*c:inverse()
g.CFrame = g.CFrame*difference
Hi!
I’ve been playing with this problem by representing a camera, a gun, and a sight as basic parts, like in the image. The highlighted face is the front of the part, so it’s where the camera is looking (look vector).
If I understand correctly, the goal is essentially to position G in a way that S aligns with C.
cf:Inverse() * another cf -- same as ToObjectSpace
To get the transformation I inverted the new CFrame again and applied it to C.
local difference = G.CFrame:Inverse() * S.CFrame
G.CFrame = C.CFrame * difference:Inverse()
(On the screenshot, G is moved slightly away for better visibility.)
Perhaps the same result can be achieved differently with another set of operations, but this seems to work as expected with various angles.
2 Likes
BULK_BROGAN
(BULK_BROGAN)
December 27, 2023, 11:32pm
#3
This works. I didnt inverse the final cframe. Thank you!
1 Like
system
(system)
Closed
January 10, 2024, 11:33pm
#4
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.