Aiming system for a semi tps shoulder camera system

https://gyazo.com/9e520cc849df07000ee243e4ade0651a

The problem is the aim gui can’t just be at a fixed position, since the camera and the gun do not have the same rotation, as seen in the video above. Normally if the gun was aligned with the camera I would just put the crosshair at a fixed position, however this is not the case. How would I make it so the gui stays where the bullet’s path ends. The code I tried now is:

function WorldToScreen(Pos) --This function gets a World Position (Pos) and returns a Vector2 value of the screen coordinates
    local point = camera.CoordinateFrame:pointToObjectSpace(Pos)
    local aspectRatio = Mouse.ViewSizeX / Mouse.ViewSizeY
    local hfactor = math.tan(math.rad(camera.FieldOfView) / 2)
    local wfactor = aspectRatio*hfactor

    local x = (point.x/point.z) / -wfactor
    local y = (point.y/point.z) /  hfactor

    return Vector2.new(Mouse.ViewSizeX * (0.5 + 0.5 * x), Mouse.ViewSizeY * (0.5 + 0.5 * y))
end

local function setAbsolutePosition(gui, position)
    local relativePosition = position - gui.Parent.AbsolutePosition
    gui.Position = UDim2.fromOffset(relativePosition.X, relativePosition.Y)
end

Vec2 = WorldToScreen(SmgGun.Smg.FrontPart.CFrame.LookVector * 400)
setAbsolutePosition(Aim.ImageLabel, Vec2)

Using some functions shown on the devforum.

Here is the game if you want to see how the aim destiny is dynamic and the crosshair can;t be at a fixed position, oh yah and the current crosshair doesn’t work as you see it doesn’t point to the point the bullet will land on.

Basically I want to show a gui at a 3d point space

bump, still looking for help on this

1 Like