So, I know how to get the position at the center of the screen using a ray, and I can find many topics explaining how to do this. But what would I do if I wanted to do the reverse? I have a position in the world, and I want the center of the screen to be pointing at that position, so using ScreenPointToRay at the center of the screen will always get me that position. Anyone have ideas on how to do this? I’ve tried using CFrame.new(Camera.Position,targetPoint), and that gets me kind of close, but it’s not at the center.
You can do this by setting the cframe of the player camera. You must do that using a localscript
By knowing the position you want to point the camera at, and the position the camera is at, you can do this;
CurrentCamera.CoordinateFrame=CFrame.new(“vector3 of position the camera is at here”, “vector3 of position you want to look at here”). This will set the camera cframe to the position it’s you want it to be, and make it look in the direction you want it to look at
Yes, as I mentioned in the original post, I tried that. While that looks in the direction of that point, it’s not directly in the center of the screen.
Can you show me what on the screen it points to using your method? It’s the upper left right?
The position is at the center of the glowing orb. Using CFrame.new(camera.position,ball.position), I get this. While it’s obviously focused on the orb, the orb should be in the crosshair (dead center of the screen), but it’s not.
https://gyazo.com/b3ec6f298fe10a3a0c6fee09e27a1045
I don’t think the crosshair is in the center of the screen due to coregui inset. Try enabling IgnoreGuiInset
on your crosshair screengui
The crosshair is in the center, it’s just the gif capture isn’t taking the whole screen, so it’s a little off.
That’s not what I was talking about. If your screengui doesn’t have IgnoreGuiInset enabled then it scales and shifts all gui objects inside of it down to match the screensize with the topbar excluded
Ohhh, I misunderstood. That did center the crosshair on the object, thank you. Now I just have to recalculate the ray to aim at the “new center,” but that shouldn’t be too hard.