Camera manipulation with plugin development

No matter how I seem to go about it, setting the camera position seems to be impossible with plugin development. I also cannot post in a good portion of the boards, so if this belongs somewhere else, I can’t post there, so I don’t know what you want me to do about that.

I’m making a viewmodel animation plugin for my CFrame based animations, and as you can see, you can’t clearly see all of the arc handles to rotate the arm, so I need to be able to get out of the set “Camera position”, make changes, and then reset the camera to the proper location so I can visualize how it will look when in use. The problem is, my camera reset function seems to work about 10% of the time and other times it will look off into nowhere. And when it does set itself properly, if i move even a fraction of an inch using default studio tools, I shoot off to where I was before. I assume this is because studio stores information about the camera’s coordinateframe somewhere outside of the camera object?

Anyways, here’s my code and a screenshot of the plugin so far. Any assistance is appreciated.

local toolbar = plugin:CreateToolbar("Redux Animator")
 
local loadRigButton = toolbar:CreateButton("LoadRig", "Create an arm-set", "rbxassetid://3394625851")
local resetCameraButton = toolbar:CreateButton("ResetCamera", "Re-position the camera in the rig.", "rbxassetid://3397520948")

local PluginOpen = false


local DefaultRightArmCF = CFrame.new(.55,-.8,0) * CFrame.Angles(math.rad(90),0,0)
local DefaultLeftArmCF = CFrame.new() * CFrame.Angles(math.rad(-20),0,math.rad(10))


local ActiveWeapon = nil
local RightArm = nil
local LeftArm = nil
local CorePosition = nil
local CameraPosition = nil

local function LoadRig()
	if not PluginOpen then
		PluginOpen = true
		ActiveWeapon = game.ReplicatedStorage.ActiveWeapon:Clone()
		ActiveWeapon.PrimaryPart = ActiveWeapon.RightHandle
		ActiveWeapon.Parent = game.Workspace
	
		RightArm = game.ReplicatedStorage.RightArm:Clone()
		RightArm.Parent = game.Workspace
		
		LeftArm = game.ReplicatedStorage.LeftArm:Clone()
		LeftArm.Parent = game.Workspace
		
		CorePosition = game.Workspace.CurrentCamera.CFrame * CFrame.new(0,0,-.5)
		CameraPosition = game.Workspace.CurrentCamera.CFrame
		RightArm:SetPrimaryPartCFrame(CorePosition * DefaultRightArmCF)
		ActiveWeapon:SetPrimaryPartCFrame(RightArm.Hand.CFrame)
		LeftArm:SetPrimaryPartCFrame(ActiveWeapon.LeftHandle.CFrame * DefaultLeftArmCF)
		
		
		local RightArmRotate = Instance.new("ArcHandles", game:GetService("CoreGui"))
		RightArmRotate.Adornee = RightArm.PrimePart
	else
		PluginOpen = false
		RightArm:Destroy()
		LeftArm:Destroy()
		ActiveWeapon:Destroy()
		ActiveWeapon = nil
		RightArm = nil
		LeftArm = nil
		game:GetService("CoreGui"):ClearAllChildren()
	end
end

local function ResetCamera()
	game.Workspace.CurrentCamera.CFrame = CameraPosition
end

loadRigButton.Click:Connect(LoadRig)
resetCameraButton.Click:Connect(ResetCamera)
1 Like

I’m not sure if this is a feature request or asking how to manipulate the camera, so here are two options:

How to post a feature request

To post a post in other topics, use can use the post approval process.
Please read the rules of the developer forum before criticizing others by saying “so I don’t know what you want me to do about that.”.

  • 15.1 If you are a New Member, and you want to create a topic in a category you do not have access to, you need to take the following steps:
    1. Create your topic in the Bulletin Board category instead first. Make sure your post fulfils all the guidelines of posting in the category you actually want to post it in. Save the link to the topic.
    2. Then, put the link in a group message to Post_Approval. Make sure to mention the category you want it moved to in the title.
    3. The people in Post_Approval will then check your topic and move it to your requested category once it meets all the guidelines of that category.

Manipulating the Camera

Try setting the mode to Enum.CameraType.Scriptable, so you can override default behavior.

workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
workspace.CurrentCamera.CFrame = newCFrame
workspace.CurrentCamera.CameraType = Enum.CameraType.Fixed

Not what I needed, but thank you for the information in the first part. I adjusted my system to work with viewportframes and a reset button that moves the arm/gun instead of the camera. Works perfectly.

Huh, that is a smart solution. I guess you can move the camera or object. Have a good day.

1 Like

This is super late but I’ve run into this same issue with camera manipulation in plugins. The solution is to set the CameraType to Scriptable, set your CFrame, wait(), and restore the CameraType to Fixed. This way the Camera looks in the correct direction. If you do not want any control over the camera and just want to control its position via script, just leave it on Scriptable.