Help with CFrames

Hello, I’ve had a slight issue involving a part following a camera using CFrames, any help is appreciated. :slight_smile:

THE SCRIPT

wait()
local plr = script.Parent.Parent
local char = workspace:findFirstChild(plr.Name)
local cam = workspace.CurrentCamera
local larm = workspace.larm

game:GetService("RunService").RenderStepped:Connect(function()
	larm.CFrame = cam.CFrame * CFrame.new(-1,-0.6,-0.4) * CFrame.fromEulerAnglesXYZ(0,50,20)
	

end)

The script works fine, however would like to make the part (larm) not look so stiff, e.g so it slightly moves around like an arm. I’m wondering how I would go about this as I have tried to use math.random() and have tried inputting some math.deg values, however it results in the arm moving slightly too much than wanted.

Also, I was wondering how I would involve a tween / lerp in this instance as I assume one is needed (might be wrong).

Many thanks for reading this and helping a new scripter improve,

2 Likes

Oh for this you can just use sin to move it up and down, similar to what I did for this procedural animation using iGottics method based on the speed of the humanoid and the renderstep step. It should move it up and down try it out.

wait()
local plr = script.Parent.Parent
local char = workspace:findFirstChild(plr.Name)
local humanoidRootPart = char:WaitForChild("HumanoidRootPart")
local cam = workspace.CurrentCamera
local larm = workspace.larm

local XYVECTOR =Vector.new(1,0,1)

local cycle = 0

game:GetService("RunService").RenderStepped:Connect(function(step)
local velocityXY = humanoidRootPart.Velocity*XYVECTOR
local stepCycle = velocityXY.Magnitude*step/16
cycle = (cycle+stepCycle)%360

	larm.CFrame = cam.CFrame * CFrame.new(-1,-0.6,-0.4) * CFrame.fromEulerAnglesXYZ(0,50,20)
	larm.CFrame *= CFrame.new(0,math.cos(cycle),0)
end)
1 Like

Thank you, this solved my problem
Greatly appreciated :slight_smile: