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)
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
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.
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
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.
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
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)
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.