Model keeps rotating when tweening

Bug is pretty simple, the model keeps.
I already tried using position, it won’t work because I need to move the whole model and not just a single part.
Code so far:

local setAngle = CFrame.Angles(0,math.rad(0),0)
local TI = TweenInfo.new(5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
local tween = tweenS:Create(self.Enemy.HumanoidRootPart, TI, {CFrame = waypoints[ind].CFrame:ToWorldSpace(setAngle)})
tween:Play()

It’s because it’s trying to align for the second turn.

1 Like

Got any idea on how i could stop it from aligning the orientation?
I got the idea to use ToWorldSpace, yet I haven’t found anyone that knows how it works exactly.

1 Like

When i was making enemy path,i used 2 tweens.
If you want,i can give you a script

1 Like

Yes, that would help a lot, I would like it if possible.

1 Like
pathes = workspace.Path
count = script.Parent.Count.Value

changed = false
script.Parent.Speed:GetPropertyChangedSignal('Value'):Connect(function()
	--move:Cancel()
	changed = true
	walkto = Vector3.new(point.Position.X,point.Position.Y,point.Position.Z)
	primpos = prim.Position
	walkto = Vector3.new(point.Position.X,point.Position.Y,point.Position.Z)
	distance = (walkto - primpos).magnitude
	time = distance/script.Parent.Speed.Value
	move = serv:Create(script.CFrame,TweenInfo.new(time,Enum.EasingStyle.Linear),{Value = CFrame.new(walkto)})
	move:Play()

end)

script.Parent.Event.Event:Connect(function(point)
	i = point
	script.Parent.Count.Value = point
	script.PathNumber.Value = point
	point = pathes['Point'..i]
	changed = true
	lookat = CFrame.new(script.Parent.PrimaryPart.Position,point.Position)
	x,y,z = lookat:ToOrientation()
	rotate = serv:Create(script.rotatecframe,TweenInfo.new(0,Enum.EasingStyle.Linear),{Value = CFrame.Angles(x,y,z)})
	walkto = Vector3.new(point.Position.X,point.Position.Y,point.Position.Z)
	primpos = prim.Position
	walkto = Vector3.new(point.Position.X,point.Position.Y,point.Position.Z)
	distance = (walkto - primpos).magnitude
	time = distance/script.Parent.Speed.Value
	move = serv:Create(script.CFrame,TweenInfo.new(time,Enum.EasingStyle.Linear),{Value = CFrame.new(walkto)})
	move:Play()
end)


point = pathes['Point2']
prim = script.Parent.PrimaryPart
primcframe = CFrame.new(script.Parent.HumanoidRootPart.Position,point.Position)
x,y,z = primcframe:ToOrientation()
script.CFrame.Value = CFrame.new(prim.Position)
script.rotatecframe.Value = CFrame.Angles(x,y,z)
serv = game:GetService("TweenService")
script.CFrame:GetPropertyChangedSignal('Value'):Connect(function()
	script.Parent:SetPrimaryPartCFrame(script.CFrame.Value * script.rotatecframe.Value)
end)

script.Parent:SetPrimaryPartCFrame(CFrame.new(prim.Position) * script.rotatecframe.Value)
i = 2
while i <= 8 do
	if not move or move.PlaybackState == Enum.PlaybackState.Completed or move.PlaybackState == Enum.PlaybackState.Cancelled then
		point = pathes['Point'..i]
		script.PathNumber.Value = i
		distance = (pathes['Point'..i-1].Position - point.Position).magnitude
		lookat = CFrame.new(script.Parent.PrimaryPart.Position,point.Position)
		x,y,z = lookat:ToOrientation()
		rotate = serv:Create(script.rotatecframe,TweenInfo.new(0.1,Enum.EasingStyle.Linear),{Value = CFrame.Angles(x,y,z)})
		rotate:Play()
		walkto = Vector3.new(point.Position.X,point.Position.Y,point.Position.Z)

		move = serv:Create(script.CFrame,TweenInfo.new(distance/script.Parent.Speed.Value,Enum.EasingStyle.Linear),{Value = CFrame.new(walkto)})
		move:Play()
	end
	move.Completed:Wait()
	move2 = nil
	if not changed then
		i += 1
	else
		changed = false
	end
end
workspace.Map.Health.Value -= script.Parent.Health.Value
script.Parent.Health.Value = 0

This script i changed a lot, so there could be useless variable

And if you want to make rotate correct, you can rotate enemy,but not rotate primary part. Or in rotate tween add vector with coordinate Y,X or Z that will be 90,180 and other

1 Like

This might fix it:

local root = self.Enemy.HumanoidRootPart

local setAngle = root.CFrame.Rotation

local TI = TweenInfo.new(5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
local tween = tweenS:Create(root, TI, {CFrame = waypoints[ind].CFrame:ToWorldSpace(setAngle)})
tween:Play()

basically the angle is set to the starting one, in case the default orientation is not 0, 0, 0 causing the weird tween effect.

6 Likes

It works! Thanks a lot for your help, I really appreciate it.

2 Likes