#Help fixing target lock camera stops moving momentarily after unlocking

1 messages · Page 1 of 1 (latest)

ivory warren
#

Tried making a custom camera and lock on system, both are stored separately in a Local Script in StarterPlayerScripts.
How the camera works is by creating a part thats following the player's head and setting that part as the CurrentCamera Subject, I wanted to add a delay between the camera and the character, the lock on works as I wanted it to but whenever it's toggled off the camera stops moving for a brief moment and then returns back to the Custom camera part, it has been 8 hours and I still cant figure out how to solve the sudden stop.

Camera script: https://gist.github.com/givan-ri/e7500d7e1aff0c4443cb29a2e82735d5
Lock-On Script: https://gist.github.com/givan-ri/5744b78fb8a9c91cb8c728444201cfe8

Gist

Camera Script. GitHub Gist: instantly share code, notes, and snippets.

Gist

Lock-On Script. GitHub Gist: instantly share code, notes, and snippets.

storm shadow
#

after a bunch of looking my suspect is the tween youre using for the target lock

#

it will keep running for a short time after no longer locked on and would produce that behaviour

#

you should cancel the tween when there is no longer a lockon, what i would do is store each tween in a table tweens = {} and then when they complete or the lockon is cancelled i would remove them from the table, and when the lockon is cancelled i would call cancel() as well

ivory warren
storm shadow
#

lets gooo

#

very nice work by the way it looks really good

#

also i wonder if you could use a combination of offset and scale on your gui to determine the size of the dot, just to save on a renderstepped call

ivory warren
ivory warren
pseudo trenchBOT
#

studio** You are now Level 2! **studio

ivory warren
# storm shadow also i wonder if you could use a combination of offset and scale on your gui to ...

task.wait works but i dont knoow if it will cause lag

local function createLockOnIndicator(targetPart)
    if not targetPart then return nil end

    local indicator = Instance.new("BillboardGui")
    indicator.Size = UDim2.new(10, 0, 10, 0)
    indicator.StudsOffset = Vector3.new(0, 0, 0)
    indicator.AlwaysOnTop = true
    indicator.Parent = targetPart

    local imageLabel = Instance.new("ImageLabel")
    imageLabel.Size = UDim2.new(1, 0, 1, 0)
    imageLabel.BackgroundTransparency = 1
    imageLabel.Image = "rbxassetid://7649231250"
    imageLabel.Parent = indicator
    indicator.Name = "LockOnIndicator"

    local function updateDotSize()
        local hrp = humanoidRootPart
        local distance = (hrp.Position - targetPart.Position).Magnitude
        local maxDistance = 50
        local minSize = 5
        local maxSize = 20

        local size = minSize + (maxSize - minSize) * math.min(distance / maxDistance, 1)
        indicator.Size = UDim2.new(size, 0, size, 0)
    end

    local function update()
        while indicator.Parent do
            updateDotSize()
            task.wait(updateInterval)
        end
    end

    task.spawn(update)

    return indicator
end```
storm shadow
ivory warren
# storm shadow it actually wouldnt require any code at all! gui size can be determined by scale...

like this?? still dont know i should use offset or scale, thanks alot for recommending though!!

local function createLockOnIndicator(targetPart)
    if not targetPart then return nil end

    local indicator = Instance.new("BillboardGui")
    indicator.Size = UDim2.new(10, 0, 10, 0)
    indicator.StudsOffset = Vector3.new(0, 0, 0)
    indicator.AlwaysOnTop = true
    indicator.Parent = targetPart

    local imageLabel = Instance.new("ImageLabel")
    imageLabel.Size = UDim2.new(1, 0, 1, 0)
    imageLabel.BackgroundTransparency = 1
    imageLabel.Image = "rbxassetid://7649231250"
    imageLabel.Parent = indicator
    indicator.Name = "LockOnIndicator"

    local function updateDotSize()
        local hrp = humanoidRootPart
        local distance = (hrp.Position - targetPart.Position).Magnitude
        local maxDistance = 50
        local maxOffset, minOffset = 150, 37.5
        local offsetFactor = math.clamp(1 - (distance / maxDistance), 0, 1)
        local finalOffset = maxOffset + (minOffset - maxOffset) * offsetFactor
        local minDotSize = 125
        finalOffset = math.max(finalOffset, minDotSize)
        indicator.Size = UDim2.new(0, finalOffset, 0, finalOffset)
    end

    local function update()
        while indicator.Parent do
            updateDotSize()
            task.wait(updateInterval)
        end
    end

    task.spawn(update)

    return indicator
end
storm shadow
#

i mean that it wouldnt need any code to change the size

#

you can just play around with it in studio to figure out what scale and offset sizes feel right to you

#

so no need to dynamically update it based on player distance with your updateDotSize() function

#

youre just instead taking advantage of scale giving a decent baseline size for when really close to the gui and offset setting a minimum size when far away so it doesnt get too small

ivory warren
#

but now i got a new problem

#

i kinda forgot to ask, how do you make it so the character will face to the direction to the part, not the actual part itself?