Lets go! it looks really good lemmie know if you dont understand something I did.
local cam = workspace.CurrentCamera
local plr = game.Players.LocalPlayer
local Mouse = plr:GetMouse()
plr.CharacterAdded:Wait()
--local cas = game:GetService("ContextActionService")
game:GetService("RunService").RenderStepped:Connect(function()
cam.CameraType = Enum.CameraType.Scriptable
-----Positions
local hrp = plr.Character:FindFirstChild("HumanoidRootPart")
if not hrp then
return
end
local mousepos = Mouse.Hit.Position
local CharacterPosition = hrp.Position
--------------------------------------
-- You can replace this manually if ya like
local MaxLength = 2
-- there are a couple thins I should explain here:
-- .Unit takes a Vector3 and turns it to the length of 1 ( Normalized vector ), .Magnitude is the length of the vector
-- I wanted to cap the vector so i got the Normalized vector and multiplied it by a Clamped length ( limited )
-- I then used this vector to lerp the direction from the character to the mouse ( ur camera Lookat position )
local ChartoMouse = (mousepos - CharacterPosition).unit * math.clamp( (mousepos - CharacterPosition).Magnitude , 0, MaxLength)
local Lookat = CharacterPosition:Lerp(CharacterPosition+ChartoMouse,0.75)
cam.CFrame = cam.CFrame:Lerp(CFrame.new(hrp.Position + Vector3.new(0, 20, 15),Lookat),0.1)
-- It looks pretty good :D
end)
So the thing is ive added it but it didn’t work for me. Do i need to add it with the old script or delete the old script and implement the one you send
Oh so the camera wont go closer to the camera or further? I think I can make that possible id probably just fix the mouse position vector to keep the players z axis
-- I Changed a few things ( i added this next line underneath local CharacterPosition )
mousepos = Vector3.new(mousepos.X,CharacterPosition.Y,CharacterPosition.Z)
-- I made max length 15
-- Lookat lerp % is 0.2
-- Lerp % is 0.2 for the camera
Wait sorry that was a bad example. Maybe this one is a better example i just want it to move a little bit you know camera dont have to stay on the same posistion but no rotation
Couple changes I don’t remember what I changed though so here’s the entire script:
local cam = workspace.CurrentCamera
local plr = game.Players.LocalPlayer
local Mouse = plr:GetMouse()
plr.CharacterAdded:Wait()
--local cas = game:GetService("ContextActionService")
game:GetService("RunService").RenderStepped:Connect(function()
cam.CameraType = Enum.CameraType.Scriptable
-----Positions
local hrp = plr.Character:FindFirstChild("HumanoidRootPart")
if not hrp then
return
end
local mousepos = Mouse.Hit.Position
local CharacterPosition = hrp.Position
mousepos = Vector3.new(mousepos.X,CharacterPosition.Y,CharacterPosition.Z)
--------------------------------------
local Unit = (mousepos-CharacterPosition).Unit
local distance = math.clamp((mousepos-CharacterPosition).Magnitude,0,10) -- 10 is max side to side
local ChartoMouse = CharacterPosition:Lerp(CharacterPosition+Unit*distance,0.25)
cam.CFrame = cam.CFrame:Lerp(CFrame.new(ChartoMouse + Vector3.new(0, 20, 15),ChartoMouse),0.2)
-- It looks pretty good :D
end)
mousepos = Vector3.new(mousepos.X,CharacterPosition.Y,CharacterPosition.Z)
^^^
This line is whats locking the y and z axis
you can change Character Position for mouspos and it will unlock the axis