How to make a custom camera look at mouse position?

Hi, so I’m working on improving my custom camera system for a small FPS game I’ve been working on. I found a better method I’ve been using, instead of custom camera work. What I did was I set the player’s camera type to Custom, and I assigned the CameraSubject to a part to focus on, and from there the player was able to look around the map while also locking in place. However, there’s limitations to this. I thought of adding some camera recoil effects, but unfortunately I can’t seem to modify the camera’s CFrame while the player is able to move it by themself.

I tried experimenting with other options that involve setting the camera type to Scriptable, locking it in place completely, and then updating the camera’s look direction every render step. However, I tried this and the camera became very glitchy and undesirable, not smooth at all. I tried the following code:

world_camera.CFrame = CFrame.new(camFocus.Position, mouse.Hit.Position)

Not really sure what else I could try to get a better effect. It also glitches out if the mouse is staring at the ground or in the sky. :confused:

Any help is appreciated, thanks!

you want to put your game in first person but look at the position of the mouse?? i’m sorry i didn’t understand very well

I want to position the camera at a set point, and then every frame I want to update its looking direction to point towards the mouse’s position in the game world. When I attempted to do this, I got really glitchy results and it was absolutely nowhere near where I wanted it to be. It spun around too quickly, when my mouse was pointed at the ground the camera would just spin and get all funky, and it’s too hard to control.

This is because when the custom camera’s position goes to the mouse, the mouse doesn’t move with it so it’s like putting a cylinder in a loop hill that has speed boosters which means it never stops.

So i still don’t know if this is possible to do but good luck.

Edit: It’s not what you want but you could make the camera lerp to the mouse’s position slowly so it doesn’t like spin all the place around, but since it’s slow you wouldn’t want that but it’s an idea.

1 Like