How can I fix camera follow mouse when looking up or down?

You can write about your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I was wanting to make a drone.

  2. What is the issue? The issue is the camera glitching when it looks up or down.

  3. What solutions have you tried so far? I attempted to find one but was never successful.

Video:

Code:

-- Here what it do.
local Direction = Camera.CFrame.Position + (Mouse.Hit.Position - Camera.CFrame.Position)
local BodyGyro = DronePart.BodyGyro

BodyGyro.CFrame = CFrame.lookAt(DronePart.CFrame.Position, Direction)

Any assistance you can provide would be greatly appreciated!

1 Like

local Camera = workspace.CurrentCamera
local Mouse = Camera.CFrame.Position + (Camera.CFrame.LookVector * 100)
local DronePart = script.Parent.Parent
local Direction = Camera.CFrame.Position + (Mouse.Hit.Position - Camera.CFrame.Position)
local BodyGyro = DronePart.BodyGyro

BodyGyro.CFrame = CFrame.lookAt(DronePart.CFrame.Position, Direction)

So I was able to find a solution to this. I found a solution that allowed me to make this work.
Code:

local DronePart = script.Parent
local DroneCamera = workspace.CurrentCamera
local Mouse = DroneCamera.CFrame.Position + (DroneCamera.CFrame.LookVector * 100)
local Direction = DroneCamera.CFrame.Position + (Mouse.Hit.Position - DroneCamera.CFrame.Position)
local BodyGyro = DronePart.BodyGyro
local MousePos = game.Players.LocalPlayer:GetMouse().Hit.p
local BodyPos = DronePart.BodyGyro.CFrame.Position
local AngleOfRotation = math.atan2(MousePos.x - BodyPos.x, MousePos.z - BodyPos.z)

BodyGyro.CFrame = CFrame.Angles(0, AngleOfRotation, 0)

Video:

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.