How to change only the orienation of a CFrame?

The problem I am having is that it is impossible (as far as I know) to change the Orientation/Rotation property of a CFrame by itself. You can change the Rotation and Position of a part separately.

The reason I can’t just change the Rotation of the part is because it is the character’s PrimaryPart. Changing the Rotation of the PrimaryPart only affects the PrimaryPart and not all parts within the model. The way to do that is to change its `CFrame’ which has to change position and orientation at the same time.

That is the crux. Changing the CFrame’s Orientation HAS to change position along with it. I can’t do that because I am tweening the value.
A video of the issue is shown below.

The goal is to create a sliding mecahnic that orients the player where the camera is facing (point of the dir variable)

All relevant code:

humanoid.JumpHeight = 0
humanoid.WalkSpeed = 0
sliding.Value = true
local i = 1000
task.spawn(function()
	while i > 0 do
		if sliding.Value == false then break end
		i -= 1
		local dir = cam:ViewportPointToRay(cam.ViewportSize.X/2, cam.ViewportSize.Y/2, 0).Direction
		local speed = i*0.1
		
		hrp.AssemblyLinearVelocity = hrp.CFrame.LookVector * speed
				
		slidingTween = TS:Create(hrp, TweenInfo.new(0.02, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), 
			{["CFrame"] = CFrame.lookAlong(hrp.Position, Vector3.new(dir.X, 0, dir.Z))})
		slidingTween:Play()
		task.wait(FRAME_TIME) --0.017
	end
end)
2 Likes

This might not be the correct answer but can’t you just set the CFrame in the tween to be multiplied with a CFrame.Angles() ?

Also, not relevant, but you can use a for speed = 100, 0, -0.1 do end instead of a while loop for that.

2 Likes

Unfortunately, no. If you do something like

slidingTween = TS:Create(hrp, TweenInfo.new(0.02, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), 
			{["CFrame"] = CFrame.Angles(0, math.rad(90), 0)})

it assumes the position to be (0,0,0), which won’t work for me. The position has to be the HumanoidRootPart’s original position. As I explained above I can’t just do

slidingTween = TS:Create(hrp, TweenInfo.new(0.02, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), 
			{["CFrame"] = CFrame.new(hrp.Position) * CFrame.Angles(0, math.rad(90), 0)})

because it will reposition the HumanoidRootPart back to where it was when the tween started. That is what creates the jitter effect seen in the video. Thanks.

Just saw your edit. Yeah, I realized that, but it’s just temporary code so right now it doesn’t really matter.

1 Like

he meant multiplying current cf with CFrame.Angles
CFrame.new(hum.pos) * CFrame.Angles(math.rad(45), 0 , 0)

1 Like

What exactly is the goal of the script? Are you trying to tween the player towards a new direction?

it jitters because it doesnt update hrp.Position while doing the tween, considering using lerping instead of tweening

1 Like

I would guess that it is stuttering more because there are 3 (or so) factors influencing position.

  1. Tween
  2. AssemblyLinearVelocity
  3. Regular player movement (if enabled)
1 Like

its jittering because when tween is active, it doesnt use the latest hrp.Position, so it snaps back to the old one, and since tween is 0.2 seconds long, u have alot of tweens therefore alot of jitters

1 Like

Oh wait try

slidingTween = TS:Create(hrp, TweenInfo.new(0.02, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {
	CFrame = CFrame.lookAlong(hrp.Position, Vector3.new(dir.X, 0, dir.Z)):ToOrientation()
})

(Attempting to eliminate positional components of CFrame)

1 Like

A lot of information lol. The goal is to create a sliding mechanic that orients the player where the camera is facing (point of the dir variable). Sorry for not clarifying that in the original post. I’ll add that now.

I have not tried lerping yet. To be honest, I forgot it existed. I’ll try that.

Oh yeah and there is no movement enabled. I forgot to add that part of the script. mb. It’s there now.

The reason I am using Tweening (or lerping) is because the player rotation is very sudden and not smooth.

2 Likes

Unless I am doing something wrong (which is very likely since this is the first time in a while I have even touched lerping), this won’t work for me because lerping requires a for loop. If I use a for loop, I need to use task.wait() of which takes way too long for the rotation to work. It either doesn’t look smooth (high increment like 0.5) or it takes too long (low increment like 0.01) and the sliding stops.

Code:

for cfI = 0, 1, 0.1 do
	hrp.CFrame = hrp.CFrame:Lerp(CFrame.lookAlong(hrp.Position, Vector3.new(dir.X, 0, dir.Z)), cfI)
	task.wait(FRAME_TIME)
end
1 Like

add more iterations, 0.1 > 0.01 and ajust FRAME_TIME

1 Like

why do u even want interpolation on this? why not just change cframe whenever cframe changes

1 Like

FRAME_TIME is 0.017, that is so FPS unlockers don’t break anything. Removing it (1 frame wait) yields the same result. As I said, low values make the “sliding” stop for some reason.

As for why I am interpolating this, there is a noticeable stutter in the character’s rotation when you just update it when it changes. Video below.

Just realized it’s not noticeable in the preview. You have to click on the YouTube link. Sorry about that.

Code without interpolation:

humanoid.JumpHeight = 0
humanoid.WalkSpeed = 0
sliding.Value = true
task.spawn(function()
	for i = 100, 0, -0.1 do
		if sliding.Value == false then break end
		local dir = cam:ViewportPointToRay(cam.ViewportSize.X/2, cam.ViewportSize.Y/2, 0).Direction	

		hrp.AssemblyLinearVelocity = hrp.CFrame.LookVector * i
		hrp.CFrame = CFrame.lookAlong(hrp.Position, Vector3.new(dir.X, 0, dir.Z))

		task.wait(FRAME_TIME)
	end
end)

you need to use deltaTime if you want to account for fps

I am aware. It is easier to just have a set value that I can use anywhere. Anyways, do u have any more ideas? cuz I’m stumped

I know that you are trying Lerping now but did you try this?

1 Like

Yes, the problem is ToOrientation returns 3 numbers which is the rotation of the CFrame. I could use that outside of the tween to get rotation values, but then I would end up having to set the position which would create the jitter effect again.

The solution you showed doesn’t work because it returns 3 numbers, which errors because CFrames cannot be set to a number value.

I have thought about it more and I think I’m going to try to tween Rotation and try to have it influence the other parts of the character. Can’t do it rn because I’m at school and they blocked Studio. I’ll update how that goes once I get home.

orientation is a part of the cframe, you can change it directly by editing the second vector3, e.g CFrame.new(posv3, orientation)