How do i tween ONLY the cframes rotation / angle, while keeping the position snapped and constant

i am just trying to make my viewmodels rotate smoothly without the jittery movement when position is tweened really fast

i have been looking around and have found nothing it would be a great help

this is in a renderstepped loop btw :

local targetCFrame = cam.CFrame * CFrame.new(0,-1.5,0) * CFrame.Angles(0,0,0)

local tween = TweenService:Create(ViewModel.PrimaryPart, vmInfo, {CFrame = targetCFrame})
tween:Play()

1 Like

You should try lerping and ToOrientation()

even when i get the cameras x,y,z with ToOrientation() and try to use them in a orientation with a vector3.new() it wont work even in math.deg() it just rotates super fast and moves into the ground

I’m not really sure what you mean by “jittery movement when the position is tweened really fast”. Can you provide a video?

Have you tried using the LookAt feature of CFrame?

-- if "cam" is a Camera, use CFrame.Position, otherwise just cam.Position
local targetCFrame = CFrame.new(cam.CFrame.Position, target.Position)

local tween = TweenService:Create(ViewModel.PrimaryPart, vmInfo, {CFrame = targetCFrame})
tween:Play()

You can also provide more code or explanation for further assistance.

I only read the title so I’m guessing you need anchor position cuz that locks the position when an object is rotated.

I am a bit unsure of what you are trying to do


In the code you have provided, the * CFrame.Angles(0,0,0) does nothing, so that can be removed, as for the CFrame.new(0,-1.5,0), it moves the same distance no matter the frametime and fps, which is not idea, you can change it to CFrame.new(0,-1.5*60*dt,0). dt being delta time, the time between frames. At 60 fps, it is 1/60


As for answering the title, if you want to tween the rotation, and not change the position, you’d have to do something like this (it would have to be repeated every time the tween ends)

local targetCFrame = ViewModel.PrimaryPart.CFrame * CFrame.Angles(0,math.rad(180),0) -- Can't do 360 in one go, it just wont rotate

local tween = TweenService:Create(ViewModel.PrimaryPart, vmInfo, {CFrame = targetCFrame})
tween:Play()

Or, without using TweenService

local ROTATION_SPEED = math.rad(30) -- 30° per second

local initialCFrame = ViewModel.PrimaryPart.CFrame

RunService.RenderStepped:Conncect(function() 
	ViewModel.PrimaryPart.CFrame = initialCFrame * CFrame.Angles(0,ROTATION_SPEED*os.clock(),0)
end)

os.clock() can be replaced with tick(), or time(), or whatever. By using Unix time, this replaces the need to use delta time

thank you im still new to this and still trying to figure stuff out

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.