You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
I am making an over the shoulder camera system for my gun, everything works as it should but I want to create a tweening effect for when I aim my gun so it tweens into the camera.
- What is the issue? Include screenshots / videos if possible!
It does tween into the camera just fine, but it continues tweening and it makes the camera sway, i just want it to tween the transition from the regular camera to the Over the shoulder offset, i dont want any sort of swaying effect, it messes with how the camera functions anyway
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Not sure how to go about fixing this, video on how it currently works below
Code:
local function Client_Aim(Began)
local Found_Gun = Find_Weapons()
if Found_Gun == nil then return end
if Began then
local x, y = CurrentCamera.CFrame:ToOrientation()
xAngle = math.deg(y)
yAngle = math.deg(x)
Humanoid.AutoRotate = false
if Character and HumanoidRootPart then
Player:SetAttribute("Aiming", true)
ContextActionService:BindAction("PlayerInput", PlayerInput, false, Enum.UserInputType.MouseMovement)
RunService:BindToRenderStep("CameraUpdate", Enum.RenderPriority.Camera.Value, function()
local StartRootCFrame = CFrame.new(HumanoidRootPart.CFrame.Position) *
CFrame.Angles(0, math.rad(xAngle), 0) *
CFrame.Angles(math.rad(yAngle), 0, 0)
local CameraCFrame = StartRootCFrame:PointToWorldSpace(Offset)
local CameraFocus = StartRootCFrame:PointToWorldSpace(Vector3.new(Offset.X, Offset.Y, -100000))
--CurrentCamera.CFrame = CFrame.lookAt(CameraCFrame, CameraFocus)
local LookingCFrame = CFrame.lookAt(HumanoidRootPart.Position, CurrentCamera.CFrame:PointToWorldSpace(Vector3.new(0,0,-100000)))
HumanoidRootPart.CFrame = CFrame.fromMatrix(HumanoidRootPart.Position, LookingCFrame.XVector, HumanoidRootPart.CFrame.YVector)
game:GetService("TweenService"):Create(CurrentCamera, TweenInfo.new(1), {CFrame = CFrame.lookAt(CameraCFrame, CameraFocus)}):Play() -- this is where it's tweened
end)
end
end
if not Began then
Player:SetAttribute("Aiming", false)
Humanoid.AutoRotate = true
ContextActionService:UnbindAction("PlayerInput")
RunService:UnbindFromRenderStep("CameraUpdate")
game:GetService("ReplicatedStorage").GunAimtoCamear:Fire(xAngle, yAngle)
end
end