Part is rotating in a tween when it is not supposed to

I’m currently trying to Tween a part (a custom NPC’s Root part) to a position but keep it’s rotation the same. The part is moving but it is also rotating, and rotating to a rotation that isn’t even the one defined.

seven
Original Position & Rotation - Standing upright


^ What happens.

I have tried almost every solution I could find, that is, using .Angles or various other methods of getting rotation but none of them have worked, all producing the same or worse results.

local distance = (pointToGo.Position - npcRoot.Position).Magnitude
		
--print(npcRoot.Rotation)
local moveToDoor = tweenService:Create(npcRoot, TweenInfo.new(1*(distance/10), Enum.EasingStyle.Linear), 
		{CFrame = CFrame.new(Vector3.new(15.5, 46.5, 55.8), npcRoot.Rotation)})
		
moveToDoor:Play()
moveToDoor.Completed:Wait()
--print(npcRoot.Rotation)

wut is that npcRoot.Rotation inside the Cframe thingy?

does it rotate every time it moves or something?

Why don’t you use a humanoid to move the npc?

The npcRoot.Rotation is there as the final rotation for the tween in an attempt to keep the objects rotation instead of going to 0,0,0. It does not work.
The object is rotating when its just supposed to be moving.

Frankly, I havent tried using MoveTo because it seems to play up with custom NPCs but I will try when I can, thank you for reminding me about it.

Maybe you can anchor the npcRoot before tweening?

1 Like

npcRoot.Rotation is a Vector3 value. When you are constructing new CFrame, Lua does not know that this is supposed to be rotation, and uses this CFrame constructor:

new(pos: Vector3,lookAt: Vector3)

CFrame = CFrame.new(Vector3.new(15.5, 46.5, 55.8), npcRoot.Rotation)

That means final CFrame will be reoriented towards whatever the point in space will result from rotation in degrees. For example rotation 30deg, 60deg, 90deg will result in model facing point x = 30, y = 60 and z = 90. Which is obviously rubbish.

To preserve rotation, you can subtract current position vector from CFrame and add the target one.

CFrame = npcRoot.CFrame - npcRoot.Position +  Vector3.new(15.5, 46.5, 55.8)

Hope this helps.

1 Like

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