CFrame Rotation [LERPING]

Hello. The other day I asked and got an answer to why the rotation of the turret wasn’t going in the correct direction [Lerp Rotation not facing Part].

Today I’ve got another problem. It won’t fully face “target”.

Video:

Code:


local RSS = game:GetService('RunService')
local Debris = game:GetService('Debris')
local EngineOne = false

for i,v in pairs(script.Parent:GetChildren()) do
	if v:IsA('BasePart') and v.Name ~= 'Connector' and v.Name ~= 'fff' then	
		local Weld = Instance.new('Motor6D')
		Weld.Parent = v
		Weld.Part0 = script.Parent.Connector
		Weld.Part1 = v
		Weld.C0 = script.Parent.Connector.CFrame:Inverse() * v.CFrame
	elseif v:IsA('BasePart') and v.Name == 'Connector' then
		local Weld = Instance.new('Motor6D')
		Weld.Parent = v
		Weld.Part0 = script.Parent.fff
		Weld.Part1 = v
		Weld.C0 = script.Parent.fff.CFrame:Inverse() * v.CFrame
	end
end

for ii,vv in pairs(script.Parent:GetChildren()) do
	if vv:IsA('BasePart') then
		vv.Anchored = false
	end
end

local Connector = script.Parent.Connector
local fff = script.Parent.fff
local Base = script.Parent.Base

EngineOne = true

RSS.Heartbeat:Connect(function(Delta)
	if EngineOne then

		local Target = workspace:WaitForChild('Target')	

		local Start = Connector.Motor6D.C1 
		local Finish = CFrame.new(Connector.Motor6D.C1.Position, Vector3.new(Target.Position.X, Connector.Motor6D.C1.Position.Y, Target.Position.Z)):toObjectSpace(Base.Motor6D.C1)
		Connector.Motor6D.C1 = Start:lerp(Finish, 1)
		
		
		local FinishPart = Instance.new('Part', workspace)
		FinishPart.CFrame = Finish
		FinishPart.BrickColor = BrickColor.new('Reddish brown')
		
		local StartPart = Instance.new('Part', workspace)
		StartPart.CFrame = Start
		StartPart.BrickColor = BrickColor.new('Really black')
		
		Debris:AddItem(FinishPart, Delta)
		Debris:AddItem(StartPart, Delta)
		
		
			
		RSS.Heartbeat:Wait()
	end
end)

I can provide more information if necessary. Thanks in advance for any help.

QUESTION: Why doesn’t it face the target fully, even though I use the CFrame.new(Position, LookAt) ?

EDIT 1:
Updated Code with a segment that spawns a part at the Finish and Start CFrames. They both spawn at the same position, with the exact same orientation. Here is the video:

Try using not CFrame.new() but CFrame.LookAt()

Hey, thanks for the reply, but the same problem persists.

I beliece CFrame should to relative the the motor6D.Part1.CFrame object space and not the base Motor6D.C1 object space.

Otherwise here is my solution to the turret problem, it works and you can see the CFrame tricks within the code to make CFrame.lookAt work with C0 and C1 s.

Hey, thanks for the reply

I tried this beforehand actually, and assuming we’re both thinking of the same thing. (Code for reference)

local Finish = CFrame.new(Connector.Motor6D.C1.Position, Vector3.new(Target.Position.X, Connector.Motor6D.C1.Position.Y, Target.Position.Z)):toObjectSpace(Connector.Motor6D.Part1.CFrame)
		Connector.Motor6D.C1 = Start:lerp(Finish, 1)

Using the Connector Motor6D in the toObjectSpace only causes the actual model to glitch out of the map. I also experimented with the Part0.CFrame * C0 = Part1.CFrame * C1 (If I’m remembering correctly) which provided the same result.
I’ve read your TurretController post and really liked it, so If all goes according to plan I’ll just use that.

The CFrame is kinda messed it up, it should be.

Part1.CFrame:ToObjectspace(goalCFrame)

Not

goalCFrame:ToObjectSpace(Part1.CFrame)

I believe @MrNicNac got it a bit mixed up in that other post though the concept was there just reversed :wink:

Also your goal CFrame looks kinda iffy as it also uses Object Space values of C1.Position instead of world term values like part.Position. Object space being put into object space.

What’s happening is that you are inversing the wrong CFrame which causes the behavior.

Checkout this post by @4SHN who explained it pretty well.

1 Like

Ah gotcha. Thanks for your help. Fixed the problem with the CFrame Lerping, but your module worked aswell. I’ll mark your first reply as the solution. Much appreciated!

1 Like