Tweening position makes the character spins but on CFrame the character won't

So I was trying to tween my character to the position with raycasting, but, my character suddenly spins and stops after reaching the goal. On the other hand, when I tween my character’s CFrame it doesn’t make me spin. Please watch the clip below

Tweening with Position:
https://gyazo.com/5a421c2e600f9936cbc3762ea9dc2a62

Tweening with CFrame:
https://gyazo.com/0dfda6120f52fdc310ac7791e941603a

My goal is to tween my player’s position to the raycast so it will keep my player’s orientation.

here’s the code

local ray = Ray.new(Player.Character.HumanoidRootPart.Position,Player.Character.HumanoidRootPart.CFrame.LookVector*range)
	local blah,hitpos = game:GetService("Workspace"):FindPartOnRayWithIgnoreList(ray,{Player.Character})

	local movetweener = coroutine.wrap(function()
		local tweenInfo = TweenInfo.new(0.3, Enum.EasingStyle.Circular, Enum.EasingDirection.Out)	
		local Goal = {}
		if hitpos then
			humanoid.Parent["HumanoidRootPart"].Anchored = true
			Goal.Position = hitpos - (hitpos - humanoid.Parent["HumanoidRootPart"].Position).unit*4
		else
			Goal.CFrame = humanoid.Parent["HumanoidRootPart"].CFrame*CFrame.new(0,0,-range)
		end	
		local Tween = TweenService:Create(humanoid.Parent["HumanoidRootPart"], tweenInfo, Goal)	
		Tween:Play()	
		Tween.Completed:Connect(function(playbackState)
			humanoid.Parent["HumanoidRootPart"].Anchored = false
		end)
	end)
	movetweener()

I feel like in this case CFrame isn’t the ideal thing to use, because it ends up moving the character to the lookvector of the target.

If you want to bring the character to the ray’s position you just need to use hitpos.Position

1 Like

I had this issue awhile ago and I found that tweening the position causes the joints to become inconsistent with the part whereas CFrame causes the joints to remain consistent.

So what I’d do is create a new CFrame from the goal position, then use CFrame:ToOrientation to maintain the orientation:

Goal.CFrame = CFrame.new(hitpos - (hitpos - humanoid.Parent["HumanoidRootPart"].Position).unit*4) * CFrame.Angles(humanoid.Parent.HumanoidRootPart.CFrame:ToOrientation())
2 Likes

Worked perfectly! Thank you very much!

1 Like