I want my camera to be able to move along with the mouse as shown below.
I’ve considered a few solutions such as lerping a camera part, but I’m not sure what would be the optimal solution.
I want my camera to be able to move along with the mouse as shown below.
I’ve considered a few solutions such as lerping a camera part, but I’m not sure what would be the optimal solution.
Is this what you’re looking for?
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local distance = 50
local rangeMultiplier = 2
local player = Players.LocalPlayer
local camera = workspace.CurrentCamera
local middleLocation: BasePart = workspace:WaitForChild("X") -- update this, you could have a platform for the mouse to run along as this.
camera.CameraSubject = middleLocation
RunService.RenderStepped:Connect(function()
local mouse = player:GetMouse()
local hitLocation = (mouse.Hit.Position * rangeMultiplier) - (middleLocation.Position)
print(mouse.Hit.Position)
camera.CFrame = CFrame.new(hitLocation + Vector3.yAxis * distance) * CFrame.Angles(math.rad(-90), 0, math.rad(-90))
local p = Instance.new("Part")
p.Size = Vector3.new(1,1,1)
p.CFrame = camera.CFrame - (Vector3.yAxis * distance)
p.CanCollide = false
p.CanTouch = false
p.CanQuery = false
p.Transparency = 0.5
p.Parent = workspace
end)
That seems to be what I’m looking for, but I’m not too sure about the cloned parts flowing around as it moves or the boundary being set to just a part
Update: it is a bit jittery in certain spots when I set the “middleLocation” to HRP due to it now calculating the camera height from the HRP’s position. That would be my only complaint for that script, but thank you nonetheless. I will try to polish it before setting the solution.
New issue I have encountered.
The further the player strays away from the “middleLocation”, the less centered they will get until eventually they are off the screen.
I apologize if I didn’t make this clear before.
just set middlelocation to humanoidrootpart.position
What is your “MiddleLocation” set to? I’m trying to recreate the issue with it being the HumanoidRootPart, but there seems to be no issue.
I changed local middleLocation: BasePart = workspace:WaitForChild("X")
to local middleLocation: BasePart = LocalPlayer.Character.HumanoidRootPart
.
I’m not sure what is going wrong here.
Works fine for me. I don’t know what the issue could be.
it appears that I can’t change the rangeMultiplier
or else that issue occurs. It must be at 2.
Found the issue.
update this line:
local hitLocation = (mouse.Hit.Position * rangeMultiplier) - (middleLocation.Position)
to this:
local hitLocation = (mouse.Hit.Position * rangeMultiplier) - (middleLocation.Position * (rangeMultiplier - 1))
Hope this works.
There’s a new issue that I can’t seem to solve. The camera will instead base its distance from a wall instead of the HRP if the player is close enough to a wall, and the mouse is on the other side of the wall opposite the player.
Would it be possible to keep the distance between the player and the camera static?