I’m trying to make a ui effect like the game called “Watch dogs 2” (gave an image reference below) need the line to be starting from right on top my menu and it should end on a part that i chose here.
Can anyone show a better way?
For that exact effect you can just place 2 attachments (at player position and target position) and create a beam between them. You don’t really need UI here. Another thing is creating a part from your character to target and adding a decal to it or a billboard Gui if that suits you more.
Unfortunate, maybe this code will work? I used this instead of editing yours as I don’t understand most of the stuff you did and felt they were random.
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local currentCamera = workspace.CurrentCamera
workspace:WaitForChild("Part")
local line = Instance.new("Frame")
line.AnchorPoint = Vector2.new(0.5, 0.5)
line.Size = UDim2.new()
line.Parent = script.Parent
-- This is a separate function in case you want to add something to it.
local function getPosition2D(vector3: Vector3): Vector2
return currentCamera:WorldToScreenPoint(vector3)
end
local function update(line: Frame)
local origin = getPosition2D(humanoidRootPart.Position)
local endPoint = getPosition2D(game.Workspace.Part.Position)
local netVector = endPoint - origin
local length = math.sqrt(netVector.X ^ 2 + netVector.Y ^ 2)
local midpoint = Vector2.new((origin.X + endPoint.X) / 2, (origin.Y + endPoint.Y) / 2)
local theta = math.deg(math.atan2(originY - endPointY, originX - endPointX))
line.Position = UDim2.fromOffset(midpoint.X, midpoint.Y)
line.Rotation = theta
line.AnchorPoint = Vector2.new(.5, .5)
line.Size = UDim2.new(0, length, 0, 2)
end
RunService.RenderStepped:Connect(function(deltaTime: number)
update(line)
end
Yes, you need to check if the target is offscreen, the getPosition2D function should return a boolean too which indicates whether or not the item is on screen, if that boolean is false for either of the parts then just hide the line.
Thank you all for helping me out! @CodyTheDwagon it works perfectly as i wanted it to be! Thank you @msix29 assisting me!!! I would give both of you solutions but its not letting me Ya’ll really good at math!