CFrame is changing without input

If you’ve ever played League of Legends you’ll know that when you put your mouse to the edges of the screen it moves the camera, I’m trying to achieve a similar effect as seen in that game using mouseentered, loops, and a part, the camera follows the part.

First, I have a part that follows the character, it doesn’t matter yet and the camerapart that’s being used for the smooth camera effect follows the character right now.
Second, when I hover over these GUIs I want the camera to move in one direction, left of the screen goes left, top of the screen goes up, so on.

It’s working sorta but despite me not changing the CFrame values, the part is moving in different directions, like this:

Launch 1:
Gyazo
Launch 2:
Gyazo

These two launches are right after another, I thought maybe I had to let the camera and MouseFollowPart settle for a minute but that wasn’t it, same issue.

Here’s the localscript under that top GUI.

script.Parent.MouseEnter:Connect(function()
	script.Parent.IsMouseHere.Value = true
end)

script.Parent.MouseLeave:Connect(function()
	script.Parent.IsMouseHere.Value = false
end)

local Player = game.Players.LocalPlayer
local MFP = Player.Character:WaitForChild("MouseFollowPart")

script.Parent.IsMouseHere:GetPropertyChangedSignal("Value"):Connect(function()
	Player.PlayerScripts.CameraScript.IsFollowingMouse.Value = true
	Player.Character:FindFirstChild("MouseFollowPart").PositionUpdater.Enabled = false
	repeat
		MFP.CFrame = MFP.CFrame * CFrame.new(0,0,math.rad(200))
		wait(.01)
	until script.Parent.IsMouseHere.Value == false
end)

The camera isn’t at fault here it’s the MouseFollowPart, the Camera follows the part just fine, I disable the position updater for the part on mouseenter, there’s nothing else changing the CFrame of the part, does anyone know what’s happening here?

Hi, I looked at your script and I think the issue comes from this line:

`MFP.CFrame = MFP.CFrame * CFrame.new(0,0,math.rad(200))`

CFrame.new(x, y, z) creates a new CFrame position offset (it moves the part).
It does not rotate. That’s why your part is moving in strange directions.

If you want to rotate, you should use CFrame.Angles() instead:

`MFP.CFrame = MFP.CFrame * CFrame.Angles(0, math.rad(2), 0)`

This rotates the part around the Y axis smoothly.
For example:

  • CFrame.Angles(math.rad(2), 0, 0) → rotates on X
  • CFrame.Angles(0, math.rad(2), 0) → rotates on Y
  • CFrame.Angles(0, 0, math.rad(2)) → rotates on Z

So just replace CFrame.new(0,0,math.rad(200)) with the correct CFrame.Angles(...).

Sorry if I accidentally wrote nonsense or stupidity.

No it’s perfect, I figured out the rotation value changed too, your solution was right. Thanks!

1 Like

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