roblox 与 cframe 的斗争

问题描述 投票:0回答:0

我最近在 roblox 上制作了一款类似“最强战场”的游戏,但遇到了问题 由于我的英语不好,我无法解释这个问题,但这是问题的视频

链接

正如您在视频中看到的那样,它有时可以按预期工作,但有时它只是被破坏了 (顺便你可以在视频上看到控制台)

没关系,这是我的代码:

`本地hitbox = script.Parent 本地玩家= hitbox.Stats.Player 本地 tweenservice = 游戏:GetService("TweenService")

hitbox.Touched:Connect(函数(命中) 本地人形 = hit.Parent:FindFirstChild("Humanoid") 如果是人形那么 如果player.Value ~= hit.Parent.Name 那么 hitbox.CanTouch = false 本地 plr = game.Players:WaitForChild(player.Value) 游戏.ReplicatedStorage.Ability1:FireClient(plr) 本地字符 = plr.Character 局部躯干 = char.Torso 本地 rootpart = char:WaitForChild("HumanoidRootPart") local rightarm = char:WaitForChild("右臂") 本地 char2 = hit.Parent 本地 rootpart2 = char2.HumanoidRootPart 本地头 = char2:WaitForChild("头") char.Torso.CanCollide = false char2.Torso.CanCollide = false char.Head.CanCollide = false char2.Head.CanCollide = false rootpart.Anchored = true --local oldcframe = rootpart.CFrame --char.Humanoid.AutoRotate = false rootpart.CanCollide = false rootpart2.CanCollide = false char.Humanoid.WalkSpeed = 0

        local count = 0
--      local oldpos = rootpart.Position
        while wait(0.01) do
            char.Torso.CanCollide = false
            char2.Torso.CanCollide = false
            char.Head.CanCollide = false
            char2.Head.CanCollide = false
            --rootpart.CFrame = oldcframe

            rootpart2.CFrame = torso.CFrame + (torso.CFrame.LookVector*2)
            if rootpart2.CFrame ~= (torso.CFrame.LookVector*2) then
                print("rootpart2 cframe is not same with torso cframe")
                rootpart2.CFrame = torso.CFrame + (torso.CFrame.LookVector*2)
                if rootpart2.CFrame == (torso.CFrame.LookVector*2) then
                    print("but now its same")
                else
                    print("tried to equalize the values but failed")
                end
            end
            print("torso: cframe", (torso.CFrame.LookVector*2))
            print("rootpart2 cframe:", rootpart2.CFrame)
            --  rootpart2.CFrame = rootpart2.CFrame + (-rootpart2.CFrame.LookVector*0.1)
            --  rootpart2.CFrame = rootpart2.CFrame + (-rootpart2.CFrame.UpVector*1)
            count += 1
            if count == 30 then
                rootpart.Anchored = false
                break
            end 
        end
        
        
        --char:WaitForChild("HumanoidRootPart").CFrame = char:WaitForChild("HumanoidRootPart").CFrame + (-char:WaitForChild("HumanoidRootPart").CFrame.UpVector*0.5)
        count = 0
        while wait(0.01) do
            char.Torso.CanCollide = false
            char2.Torso.CanCollide = false
            char.Head.CanCollide = false
            char2.Head.CanCollide = false
            --rootpart.CFrame = oldcframe

            rootpart2.CFrame = torso.CFrame + (torso.CFrame.LookVector*2)
            if rootpart2.CFrame ~= (torso.CFrame.LookVector*2) then
                print("rootpart2 cframe is not same with torso cframe")
                rootpart2.CFrame = torso.CFrame + (torso.CFrame.LookVector*2)
                if rootpart2.CFrame == (torso.CFrame.LookVector*2) then
                    print("but now its same")
                else
                    print("tried to equalize the values but failed")
                end
            end
            print("torso: cframe", (torso.CFrame.LookVector*2))
            print("rootpart2 cframe:", rootpart2.CFrame)
            --  rootpart2.CFrame = rootpart2.CFrame + (-rootpart2.CFrame.LookVector*0.1)
            --  rootpart2.CFrame = rootpart2.CFrame + (-rootpart2.CFrame.UpVector*1)
            count += 1
            rootpart.Anchored = false
            if count == 10 then
                break
            end 
        end
        local goal = {}
        goal.CFrame = rootpart.CFrame + (rootpart.CFrame.LookVector*35)
        local tweeninfo = TweenInfo.new(0.5)
        local throw = tweenservice:Create(rootpart2, tweeninfo, goal)
        throw:Play()
        char.Humanoid.WalkSpeed = 0
        rootpart2.Anchored = false
        char2.Head.CanCollide = true
        char.Head.CanCollide = true
        wait(0.1)
        wait()
        char.Torso.CanCollide = true
        char.Humanoid.WalkSpeed = 16
        --char.Humanoid.AutoRotate = true
        rootpart.CanCollide = true
        rootpart2.CanCollide = true
        char2.Torso.CanCollide = true
        script.Parent:Destroy()
        
    end
end

完)`

如果它是硬编码的并且令人困惑,对此表示抱歉 顺便说一下,如果您可以用另一种方法做同样的事情,请告诉我,谢谢:D

我几乎尝试了一切,我在互联网上查找了所有论坛网站,但我没有找到任何东西

正如你所看到的,我稍微玩了一下代码,但不,我现在已经为这个问题苦苦挣扎了几个小时

我不知道为什么它没有显示一半的代码而不是代码示例,对此感到抱歉

注意:这不是 LookVector 的问题,我删除了它,但同样的问题仍然存在

lua roblox
© www.soinside.com 2019 - 2024. All rights reserved.