LockOn Camera Promblem

Today, I have been trying to stop the camera from going up when the dummy is near.

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local Part = Instance.new("Part")
Part.Name = "CameraLockOn"
Part.Size = Vector3.new(1,1,1)
Part.CanCollide = false
Part.Parent = workspace.CurrentCamera

local BodyPosition = Instance.new("BodyPosition")
BodyPosition.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
BodyPosition.D = 500
BodyPosition.Parent = Part

local LocalPlayer = Players.LocalPlayer or Players.PlayerAdded:Wait()
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()

RunService.RenderStepped:Connect(function()
	local Dummy = workspace.Dummy
	local CameraPostion = CFrame.new(Character.HumanoidRootPart.Position, 
    Dummy.PrimaryPart.Position) * CFrame.new(0,4,10).p
	BodyPosition.Position = CameraPostion	
		
workspace.CurrentCamera.CFrame = CFrame.new(Part.Position, Dummy.PrimaryPart.Position) 
end)

When the Player Character Gets close to Dummy, the camera Cframe would go Up, is there a way to stop camera cframe from doing that?

Idk what you are looking for but try this lol


workspace.CurrentCamera.CFrame = CFrame.new(Part.Position, Dummy.PrimaryPart.Position * Vector3.new(1, 0, 1) + part.Position * Vector3.new(0, 1, 0))

A while back I actually found problem, but i forgot about the topic, But You need to Use springs, First create, Attachment for the character, and for target object, Make sure Coils are Zero and damping. Make sure LimitEnabled is True, make sure the MaxLength is somewhere between a good spot where the camera won’t go up. I have myes on 2.5. make sure you use MinLength, because if your MinLength is low, the spring will pull you towards the target.
Also thanks for replying @Moonvane

Here the script if you want it.

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local Part = Instance.new("Part")
Part.Name = "CameraLockOn"
Part.Size = Vector3.new(1,1,1)
Part.CanCollide = false
Part.Parent = workspace.CurrentCamera

local BodyPosition = Instance.new("BodyPosition")
BodyPosition.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
BodyPosition.D = 500
BodyPosition.Parent = Part

local LocalPlayer = Players.LocalPlayer or Players.PlayerAdded:Wait()
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local Target = workspace.Dummy

local CharacterAttacmentSpring = Instance.new("Attachment")
CharacterAttacmentSpring.Name = "LockOnAttacment"
CharacterAttacmentSpring.Parent = Character.PrimaryPart

local NPCAttacment = Instance.new("Attachment")
NPCAttacment.Name = "NPCAttacment"
NPCAttacment.Parent = Target.HumanoidRootPart

local LockOnSpringConstraint = Instance.new("SpringConstraint")
LockOnSpringConstraint.Name = "LockOnSpringConstraint"
LockOnSpringConstraint.Attachment0 = CharacterAttacmentSpring
LockOnSpringConstraint.Attachment1 = NPCAttacment
LockOnSpringConstraint.Enabled = true
LockOnSpringConstraint.Visible = true
LockOnSpringConstraint.Coils = 0
LockOnSpringConstraint.Damping = 0
LockOnSpringConstraint.LimitsEnabled = true
LockOnSpringConstraint.MinLength = 1000
LockOnSpringConstraint.MaxLength = 2.5
LockOnSpringConstraint.Parent = Character


RunService.RenderStepped:Connect(function()
	local CameraPostion = CFrame.new(Character.HumanoidRootPart.Position, 
		Target.PrimaryPart.Position) * CFrame.new(0,4,10).p
	BodyPosition.Position = CameraPostion	

	workspace.CurrentCamera.CFrame = CFrame.new(Part.Position, Target.PrimaryPart.Position) 
end)
1 Like