Projecting 3d point to surface gui

I’m trying to make a holographic sight in which the reticle stays in the center of the screen. Right now I’m using a billboard gui 80 studs in front of the camera which works fine, but the reticle doesn’t clip out when it is outside the frame of the scope. I was hoping to achieve that by having the reticle in a surface gui with clips descendants enabled on the lens of the scope and projecting the 3d position of the current billboard gui onto the surface gui but I don’t know how I could go about doing this.

Is there a reason you don’t put the billboard inside the scope? since you are going to have the scope up anyway when you need the dot.

Could even have 2 one in the front and one in the back to create an aligning effect for scope movement.

If the reticle was in the scope it’d still be projected in front of the camera and would be visible when you stopped aiming in the center of the screen.

If the billboard gui was adorneed to the scope then it’d be affected by the sway of the gun which is what I’m trying to avoid.

I meant “inside” the physical scope, you wouldn’t see it on your screen unless you looked into the tube.

But, if you want to avoid sway… hmm

Have a gui dependent on the condition isAiming?
so it is active when you pull scope up and
made invisible when down

modifiable based on which scope is being used.
viewport + projected camera for zoom

Ok, I think an easier approach would to ask why don’t you just keep the scope steady in the screen? Assuming the scope is welded to something, you could update the weld each frame to keep the scope in the center of the screen.

Wait until the scoping in animation is finished, then do:

local DISTANCE = 4

local Stepped = game:GetService("RunService").RenderStepped:Connect(function()
  local TargetCFrame = Camera.CFrame.lookVector * DISTANCE
  local ScopeWeld = Scope.Weld
  local ScopeWeld.C0 = ScopeWeld.C0:CFrameToObjectSpace(TargetCFrame)
end)

I only want to keep the reticle steady, not the entire scope. And yea, the scope is welded to a gun but
I made it transparent to show off my problem better.

I just want the reticle to clip out when its no longer viewable through the scope and I think projecting onto a surface gui might work.

2 Likes

Eh, that would work but I don’t think it would be as clean as the reticle rolling in and out from the side when aiming in and out.

When zoomed in you can have it be that 80 studs away. When you unzoom just re position the reticle so that it’s in the scope. So when the player stops holding the zoom button, wait x time and put the reticle in the gun as if it was actually there. The time to wait depends on how quickly you unzoom I guess.

Surface gui wont work because a part could get in the way of the 80 studs.

just do this

local window = game.Workspace.C8.ProjectorSight --ur adornee
local camera = game.Workspace.CurrentCamera

local nCamera = Instance.new("Camera", vpf)

game:GetService("RunService"):BindToRenderStep("After Camera", Enum.RenderPriority.Camera.Value + 1, function(dt)
   local camCF = camera.CFrame
   local surfaceCF = window.CFrame * CFrame.new(0, 0, -window.Size.z/2)
   local p = surfaceCF:PointToObjectSpace(camCF.p)
   local s = p / window.Size

   vpf.Position = UDim2.new(0.5 - s.x, 0, 0.5 - s.y, 0)
   
   camera.CFrame = camCF
end)```

Well, this is the second time someone has bumped this topic but I am kinda desperate to get this function in my framework, could you elaborate on what variables are what…?

This question really should be answered at some point, since this is a great feature and I love seeing it in games.

2 Likes

aight here the place file for everyone especially @i_eetANts
explain this.rbxl (311.4 KB)
enjoy

3 Likes

Create a part that is the size of the scopePart and use mouse.Target, If the target of the mouse is the scopePart then, Make the gui visible hence make it transparent, Oh and don’t untick the scopePart’s canQuery so that the mouse.Target detects it