Basically I made a lock on script so when a player presses z there camera focuses on a torso that is near them. But this doesn't work it just completly focuses on just the enemy torso you can't see the player if they walk out of sight.. help? -script-

p = game.Players.LocalPlayer
c = p.Character
mouse = p:GetMouse()
dist = 30
function lockon(key)
	if key == "z" then
		for i,v in pairs(game.Workspace:GetChildren()) do
			if v:IsA("Model") then
				if v:FindFirstChild("Torso") ~= nil then
					local mag = (v.Torso.Position - c.Torso.Position).magnitude
					if mag <= 15 and v.Torso.Parent.Name ~= p.Name and v.Torso ~= nil then
					   print("Torso Detected!")
					end
				end
			end
		end
	end
end

mouse.KeyDown:connect(lockon)

4 comments

0

Why not make the camera behind the player's shoulder and make the focus the enemy torso.

0

Explain how I would do focus

0

Look vector and field of view?

0

Please use UserInputService instead of Mouse