Roblox Lua尝试像平台一样将零件补间并四处移动

我一直在Lua上进行补间练习,我一直在努力理解为什么我不能让自己的平台在起点和终点平台之间来回移动。首先,我将显示代码

-- Starting Variables
local TweenService = game:GetService("TweenService")
local group = game.Workspace.MovingPlatform

-- Group Variables
local part = group.Platform
local start = group.Check1
local finish = group.Check2

-- Vectors
local destination = Vector3.new(start.Position.x,start.Position.y,start.Position.z)

-- Platform Tween Info
local info = TweenInfo.new(
    1,--Length (seconds)
    Enum.EasingStyle.Linear,Enum.EasingDirection.Out,-1,--Times To Be Repeated
    true,0 --Delay
)

-- Where the destination is
local goals = { 
    Position = Vector3.new(destination)
}

-- Makes it go
local MovePart = TweenService:Create(part,info,goals)
MovePart:Play()

-- Debugging
local startPosition = Vector3.new(start.Position.x,start.Position.z)
local endPosition = Vector3.new(finish.Position.x,finish.Position.y,finish.Position.z)
local partPosition = Vector3.new(part.Position.x,part.Position.y,part.Position.z)
while true do
    print("Start Position: "..tostring(startPosition))
    print("Destination: "..tostring(destination))
    print("End Position: "..tostring(endPosition))
    print("Platform Position: "..tostring(partPosition))
    print("--------------")
    wait(3)
end

平台将移动一次,然后开始窜动并移动到任何地方,最终将停在地板上来回移动,第四次但不在正确的位置。我尝试调试以查看我的任何零件的位置是否都以某种方式发生了变化,但是一切都保持不变。也许我没有正确记录位置,但是仍然暗示我可能做错了什么?

iCMS 回答:Roblox Lua尝试像平台一样将零件补间并四处移动

在移动物体时,您可能想尝试使用CFrame而不是Position。 另外,Part.Position是Vector3,因此没有必要为Vector3创建新的Vector3。

尝试这样的事情:

-- Starting Variables
local TweenService = game:GetService("TweenService")
local group = game.Workspace.MovingPlatform

-- Group Variables
local part = group.Platform
local start = group.Check1
local finish = group.Check2

-- Set the platform part to start at Check1
part.CFrame = start.CFrame

-- Platform Tween Info
local info = TweenInfo.new(
    1,--Length (seconds)
    Enum.EasingStyle.Linear,Enum.EasingDirection.Out,-1,--Times To Be Repeated
    true,0 --Delay
)

-- Where the destination is
local Goals = { 
    CFrame = finish.CFrame -- We want it to end at the finish part's position
}

-- Makes it go
local MovePart = TweenService:Create(part,info,Goals)
MovePart:Play()
本文链接:https://www.f2er.com/1574355.html

大家都在问