Problem with CFrame

Hello!

A quick summary:
I’m looking for a way to make a new CFrame with the same orientation as an old one.

I am currently making a mantling system for my game. It works really nicely and smoothly, except you rotate. The problem is, if I don’t rotate it, it doesn’t look very smooth at all - it’s all jittery. I am using CFrame.new to make the new CFrame, and tweening to it. I’ve also tried CFrame.lookAt, and the EularAnglesXYZ functions as well. All the other posts about this didn’t work for me.

Here’s a few snippets (indentation is off because of copy and paste from my script):

--[[
"hrp" is the HumanoidRootPart of the player's character.
"ts" is the TweenService.
"camPosMagnitude" is the add factor to keep the camera height the same, I've tried without
]]

local camTween = ts:Create(workspace.CurrentCamera, TweenInfo.new(0.6, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {
		CFrame = hrp.CFrame + (Vector3.new(0, 5 + camPosMagnitude, 0) + (hrp.CFrame.LookVector * 1.5))
	})

--a bit further down the script...
local humTarget = CFrame.lookAt(
		currentMantlePos + (hrp.CFrame.Position - hrp.Parent.LeftFoot.CFrame.Position) + Vector3.new(0, addFactor, 0),
		hrp.CFrame.Position
	)
	
	local tween2 = ts:Create(hrp, TweenInfo.new(0.4, info.EasingStyle, info.EasingDirection), {
		CFrame = humTarget
	})
	
	local camTween2 = ts:Create(workspace.CurrentCamera, TweenInfo.new(0.4, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {
		CFrame = humTarget + Vector3.new(0, addFactor, 0)
	})

Video showing issue:







TLDR: I’m looking for a way to make a CFrame face the same way as another CFrame.

Any help is appreciated.

I’m still confused so I’m bumping this post

1 Like

You can look at the documentation for CFrame:ToOrientation(), maybe something like this:

CFrame = newCFrame * CFrame.Angles(math.rad(oldCFrame:ToOrientation()); -- maybe use math.rad for each axis, idk

After a bit of playing around, I got it to work! I just put the same CFrame in for both arguements. Thanks for the help, though, it helped me solve it. I’ll mark your post as solution.

Yeah, if it was a part, you would do part.CFrame *= (whatever angle/modification)

I just put CFrame because I thought you had 2 cframe values and you needed to set a part’s CFrame after adjusting both.

There’s a bit of another issue. It turns out that, when I tried it outside of first person, the character randomly faces towards the floor and then get flung. I’m currently trying to find out how I can convert CFrame:ToOrientation() to a Vector3.

Update: it half works. It still tries to rotate the player, though.

Completely fixed now, since I only need it to be first person, I removed any orientation because the camera does that automatically. Thanks for all your help, though!

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