My goal is to set the camera to a part, and rotate it depending on where the mouse is. I also would like to set some parameters on how far the player can rotate, because it isn’t realistic to be able to turn 360 degrees.
I understand how to rotate the part, and I feel like mouse.Target
would be the way to go? But I’m not totally sure so I was wondering if anybody could lead me in the right direction. I’ve looked it up and haven’t found much. Thanks!
I originally created a more complex system that uses ScreenPointToRay, but there were random glitches that would happen when the user put his mouse at the corner of the screen, so I switched to a much more simple method that works just fine.
This is how it looks:
Nothing crazy, but here’s the code I created:
local currentVector = Vector2.new(0,0)
local function calculateDistanceBetween2DVectors()
local currentMouseLocation = UIS:GetMouseLocation()
local previousVector = currentVector
local distBtwVectors = currentMouseLocation - previousVector
currentVector = currentMouseLocation
return distBtwVectors
end
local function pointCameraToMouse(input: InputObject)
if input.UserInputType == Enum.UserInputType.MouseMovement then
local movementAmt = calculateDistanceBetween2DVectors()
print(movementAmt)
Camera.CFrame *= CFrame.Angles(math.rad(movementAmt.Y / -10), math.rad(movementAmt.X / -10), 0)
end
end
function Shift.Init()
UIS.InputChanged:Connect(pointCameraToMouse)
end
Again, ScreenPointToRay is another viable option, but this is the route I went with.