The camera part or the camera?
Try to go in game and figure out if the cameraPart and your actual camera are aligned. You can do this by joining solo, switching to the server side, and checking where the cameraPart is.
Well the camera is in its correct position except its not flipped around.
Oh, so try putting mousePos back and see if it is still in the wrong pos.
Still flips around heres my code;
local mousePosX = userInputService:GetMouseLocation().X
local mousePosY = userInputService:GetMouseLocation().Y
local MAX_DIST_X = 100
local MIN_DIST_X = 16
local MAX_DIST_Y = 100
local MIN_DIST_Y = 16
local regX = (mousePosX > MAX_DIST_X and MAX_DIST_X) or (mousePosX < MIN_DIST_X and MIN_DIST_X) or mousePosX
local regY = (mousePosY > MAX_DIST_Y and MAX_DIST_Y) or (mousePosY < MIN_DIST_Y and MIN_DIST_Y) or mousePosY
local mousePos = Vector3.new(regX, regY, 0)
local result = {CFrame = CFrame.new(cameraPart.Position, mousePos)}
local t1 = tweenService:Create(cameraPart, TweenInfo.new(1), result)
t1:Play()
and when I commented out the
--t1:Play()
the turn around thing didnt happen.
Oh I think I know the problem. It is too sensitive.
local regX = 30 / ((mousePosX > MAX_DIST_X and MAX_DIST_X) or (mousePosX < MIN_DIST_X and MIN_DIST_X) or mousePosX)
local regY = 30 /((mousePosY > MAX_DIST_Y and MAX_DIST_Y) or (mousePosY < MIN_DIST_Y and MIN_DIST_Y) or mousePosY)
So, I scaled down the sensitivity by dividing a number 30
(which can be changed based on your likings) by the mouse position.
Alright good news and a little bad new good news is this fixed the glitch. Bad news is it only works on one side let me send a video to explain what I mean;
As you see if I move my cursor to the right or down it wont move the camera right or down.
Well, actually, it is working just how I expected it to! Yes, that may sound confusing, but, remember those Min Dist and Max Dist variables? Here is where they come into play.
The solution is that we figure out the size of the screen and use those variables along with an offset. Get ready for another essay lol.
First off, we need to figure out the size of the screen. To do this, we can call a property in the player’s camera that tells us the size of their screen. To do this, we just do:
workspace.CurrentCamera.ViewportSize
Next, we will add a dead-zone where regardless if the cursor moves in this area, the camera will not rotate, which is what you are looking for. Let’s say for example that you don’t want the camera to rotate if it is within 64 pixels of the edge of the screen. Below is a visual. Any time that the cursor is in the Dead Zone, the camera will not rotate. i know its not 64 pixels lol
Ok, so. First off, we need to set our minimum values, which will cover the top and the left of the screen. To do this, we simply need to change the following: Note that I set the variables to 64, but you can change them to whatever you want. Have fun, play around with it, find what fits best.
local MIN_DIST_X = 64
local MIN_DIST_Y = 64
Now, we need to set the maximum values, to do that, we need to get that little screen size that we had, since in coding, everything regarding UI starts from the top left. So, we can go all the way to the end of the screen and subtract 64 (or whatever) from it.
local MAX_DIST_X = workspace.CurrentCamera.ViewportSize.X - 64
local MAX_DIST_Y = workspace.CurrentCamera.ViewportSize.Y - 64
So, this should pretty much be it. I probably made a typo, let me know if it comes up with an error. But regardless, I believe that this should work! And remember, you can change 64 to anything, depending how much you want to constrict the camera’s movement to a certain range.
Please let me know if this helps.
It does work but I am a little confused so do you mean there is no way to make the camera rotate right or down. Or do I have to play with the values to achieve that?
Is it not rotating those ways?
correct
it is not rotating right or down. It will rotate left and up though.
here’s the code;
local mousePosX = userInputService:GetMouseLocation().X
local mousePosY = userInputService:GetMouseLocation().Y
local MIN_DIST_X = 45
local MIN_DIST_Y = 45
local MAX_DIST_X = workspace.CurrentCamera.ViewportSize.X - 64
local MAX_DIST_Y = workspace.CurrentCamera.ViewportSize.Y - 64
local regX = 30 / ((mousePosX > MAX_DIST_X and MAX_DIST_X) or (mousePosX < MIN_DIST_X and MIN_DIST_X) or mousePosX)
local regY = 30 /((mousePosY > MAX_DIST_Y and MAX_DIST_Y) or (mousePosY < MIN_DIST_Y and MIN_DIST_Y) or mousePosY)
local mousePos = Vector3.new(regX, regY, 0)
local result = {CFrame = CFrame.new(cameraPart.Position, mousePos)}
local t1 = tweenService:Create(cameraPart, TweenInfo.new(1), result)
t1:Play()
Hmm. Can you print out all four of the max/min variables and tell me their values?
print(MIN_DIST_X)
print(MIN_DIST_Y)
print(MAX_DIST_Y)
print(MAX_DIST_X)
45
45
619
1174
is what they printed.
It seems to be working normally, can you try to print regX and regY?
this printed
print(regX)
print(regY)
0.1038062283737
0.66666666666667
Can you move your cursor around for a little while then show me the output?
When doing this the values do change
0.66666666666667
0.66666666666667
0.025553662691652
0.16393442622951
heres some seperate values I grabbed
Can I see a video of it not moving down or right, as of right now?
here’s the code;
print("------------------")
print(regX)
print(regY)
hares the video;
Wait so it is not moving at all?