Need help with changing camera cframe rotation

I want to change the x value of the cframe orientation through script

my camera is attatched to a part

	cameraPartConnection = renderstepped:Connect(function()
		camera.CFrame = Drone.CamPart.WorldCFrame
	end)


i want to only be able to let the camaera look up and down to a certain amount while it is attatched to the part

How Can I do this?
Thanks

1 Like

Instead of setting the camera’s CFrame to the CamPart’s CFrame, make a new Vector3: Y and Z take from Drone.CamPart.WorldCFrame, and X also takes from it but you put it through math.clamp to have the value stay between your specified limits.

math.clamp(Drone.CamPart.WorldCFrame.X, <minVal>, <maxVal>)

https://create.roblox.com/docs/reference/engine/libraries/math#clamp

camPartCFrame = Drone.CamPart.WorldCFrame -- Storing this as a variable to lighten the size of the next line.
camera.CFrame = Vector3.new(math.clamp(camPartCFrame.X, <minVal>, <maxVal>), camPartCFrame.Y, camPartCFrame.Z)

I hope this is what you’re looking for.

1 Like

hi thanks for responding; i tried putting this in and it errors this

Unable to assign property CFrame. CoordinateFrame expected, got Vector3 - Client - DroneController:122

I dont really know what Im doing with Cframe angles

1 Like

My bad. I oversimplified this in my head.

Your CFrame is going to be composed of the position and rotation. Since the position is just your camera part’s position, you can do the following:

CFrame.new(camPartCFrame.Position) -- CFrame.new(position: Vector3) is one of a few ways to use this method.

And then the rotation follows what we described in the previous message, but correctly.

xRot, yRot, zRot = camPartCFrame:ToEulerAnglesXYZ() -- Gets the rotation values in radians.
CFrame.fromEulerAngles(math.clamp(xRot, math.rad(<minVal>), math.rad(<maxVal>), yRot, zRot) -- math.rad is used so your bounds can be input as degrees.

Then to combine the position CFrame and the rotation CFrame together you multiply them together with *. And that combined CFrame is what you set the camera CFrame to.

xRot, yRot, zRot = camPartCFrame:ToEulerAnglesXYZ()
rotationCFrame = CFrame.fromEulerAngles(math.clamp(xRot, math.rad(<minVal>), math.rad(<maxVal>)), yRot, zRot)
camera.CFrame = CFrame.new(camPartCFrame.Position) * rotationCFrame

Really hoping this is right this time, sorry. :sob:

2 Likes

sorry for late response
thank you for this, it nearly works with what Im trying to do

this is messy so let me know if i need to explain anything please

Camerapart is an attachment thats placed on the front of the drone


all code is on a runservice.Postsimulation loop
here’s what happens when I try using that code

		local xrot,yrot,zrot = CameraPart.WorldCFrame:ToEulerAnglesXYZ()
		local rotc = CFrame.fromEulerAnglesXYZ(math.clamp(xrot + math.clamp(-mouseDelta.Y / dt * 0.0001, -10,10) , math.rad(-70), math.rad(70)) , yrot, zrot)
		camera.CFrame = CFrame.new(CameraPart.WorldCFrame.Position) * rotc

Im probably doing something wrong but i cant find where


i cant Look up and down and it weirdly rotates the camera sideways

i tried something else and its close to what i want but for some looks choppy

		CameraPart.CFrame = CFrame.fromEulerAnglesXYZ(math.clamp(xrot + math.clamp(-mouseDelta.Y / dt * 0.0001, -10,10) , math.rad(-70), math.rad(70)) , yrot, zrot)
		
		camera.CFrame = CameraPart.WorldCFrame

it rotates the part attachment instead and camera follows the attachment

im guessing it looks choppy because of something to do with math.rad but im not sure

any helps appreciated

1 Like

Does it look any better if you were to rotate the attachment up and down instead of the drone part? This is the approach I took in Godot with first-person cameras, and I’m thinking that it’s choppy because your attachment is rotating around a point (the camera model’s origin I think) instead of just rotating on itself.

Sorry for not replying sooner, for some reason I wasn’t notified of this. I’ll be checking back regularly for updates.

Edit: Disregard everything I just said. I misinterpretted again.
Edit: Actually don’t disregard everything I just said. The fact that the attachment was called CamPart threw me off lol

Ok, so going off the assumption that the jitteriness of the camera is because the attachment is rotating about the origin of the model, could you see if the jitter subsides if the attachment is positioned at the origin?

1 Like

Hi, no worries, thanks for responding

it seems to be the last thing you said; i moved it to the origin position and the jittering stopped

Is there a way to fix the jittering while keeping the position where it originally was?

I’m not sure I have a solution for that. Sorry.

1 Like