How to get camera position depending on mouse position

In this photo, you see mouse in the middle of screen and screen “borders” in red color

Now question, how to get camera position like it “follows” the mouse that was in the middle of it.

In this image you see the mouse moved, and I want to get the position of camera “that like followed this mouse”

1 Like

The camera doesnt follow mouse, as you can see in your own screens even tho the mouse moved the camera is still in the same position. To get camera position you just do workspace.CurrentCamera.CFrame.Position.

But I think what you mean is like if there was a bounding box to the screen, and it followed the mouse movement, how would you get that box’s position.
If so, to get the centre of the box you need to do, Mouse.y)

If you want to get the edges of the box, just calculate them from this vector2

P.S. I like your avatar

I think he means that the camera should look at the mouse

Why? If he wants the camera to follow mouse he can either hold RMB or enable shiftlock. without those, if mouse moves freely and camera still follows mouse, it will be incredibly uncomfortable for the player.

However if thats what he wants I can provide solution for that too

1 Like

You quite didn’t understand me right, I hope this picture will give you the right idea

This small cubes inside “screens” is mouse and I wanna get the Vector3 position of camera that has blue screen

Do you mean mouseBehavior?

You don’t understand what you want.

The blue box can not have a vector3 position, as it is not a 3D object, it is a 2D plane. And I thoroughly explained how to get the vector2 position of the blue box

Nope, listen what I wrote in the message

1 Like

I know it’s hard to understand but listen again, there’s BLUE screen and there’s WHITE screen. There’s a camera that has position, it shows up the WHITE screen. I want to know camera position that shows BLUE screen.

When the player moves his mouse you want the camera to move to that position so the mouse looks like it’s stuck in the middle? That would move the camera away from his character tho…

No, I want to keep normal camera and get camera position that would have this mouse in the middle.
So we have 2 screens.
1 screen having it’s mouse anywhere
2 screen having it’s mouse in the middle (I want to get position of the camera that would have that screen)

1 Like

So you want the theoretical position of the camera?

Yeah I need CFrame, so I’ll add it to camera in viewport to make one effect.

Alright, when I get on pc, I’ll try to make one for you.

Having any ideas how can I make that?

Take mouse position and divide by screen resolution times 100, now you got the percentage change, multiple with camera CFrame, this could be the way.

made it or should I work on it?

you can try this.

local players = game:GetService("Players")

local player = players.LocalPlayer
local mouse = player:GetMouse()

local currentCamera = workspace.CurrentCamera

	local viewPortSize = currentCamera.ViewportSize
	local newPositionX , newPositionY = mouse.X , mouse.Y
	local viewPortSizeX , viewPortSizeY = viewPortSize.X , viewPortSize.Y
	local ratioX = (newPositionX / viewPortSizeX)
	local ratioY = (newPositionY / viewPortSizeY)
	local cframe = currentCamera.CFrame
	cframe *= , ratioY , 0)

When I’ve made viewport frame to see if it works and nope. It doesn’t move at all when I’m moving my mouse.

1 Like

or it moves but maybe it’s so small movement I don’t see

1 Like