Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Displacing a camera for a given displacement vector3?

Asked by 5 years ago
Edited 5 years ago

Here is a script here.

cam = game.Workspace.CurrentCamera
newrot = 0
camerarelpos = vector3.New(0,10,10) -- Distance of camera away from Subject
mouse = game.Players.LocalPlayer:GetMouse()
playerblock = Instance.New("Part")
playerblock.Parent = workspace

mouse.Button1Down:connect(function()
    if mouse.Target~=nil and mouse.Target.Name == "Plate" then
        local tar = mouse.Target
        local newloc = tar.Position +Vector3.new(0,1,0)
        local disp = (newloc - playerblock.Position) -- Displacement of the camera
        local ccam = cam.CFrame
        cam:Interpolate(ccam*CFrame.Angles(0,math.pi/2*newrot,0)* CFrame.new(camerarelpos)+disp,tar.CFrame+Vector3.new(0,1,0),1)
        playerblock.Position = newloc
    end
end)


Problem here is that I want to move the camera with the vector3 displacement, disp, so it follows the "playerblock" position, but for some reason the camera progressively Zooms out instead of maintaining the same distance over time. Is there something about CFrame that I am misunderstanding?

Answer this question