【问题标题】:How to move created objects in Roblox如何在 Roblox 中移动创建的对象
【发布时间】:2021-08-27 05:13:40
【问题描述】:

我正在 roblox studio 中制作游戏,我需要让我创建(手动创建)的对象向玩家移动。代码如下:

    local pl = game.Players.LocalPlayer
    local Money = script.Parent.Parent.Money
    Money.MoveTo(Vector3.new(player.Homeloc.Value))
    wait(5)

请帮帮我

【问题讨论】:

  • Money.MoveTo(Vector3.new(player.Homeloc.Value)) 应该会引发错误。我不确定这只是一个错字还是您根本没有阅读手册。如果有错误消息,您应该分享它们。

标签: lua roblox


【解决方案1】:

你放了一个 .在Money.MoveTo(Vector3.new(player.Homeloc.Value)) 中,MoveTo 是模型的函数,所以它必须是Money:MoveTo(Vector3.new(..))

【讨论】:

    【解决方案2】:

    按照手册中的示例有什么问题? https://developer.roblox.com/en-us/api-reference/function/Model/MoveTo

    -- define two Positions
    local startPosition = Vector3.new(-20, 10, 0)
    local endPosition = Vector3.new(0, 10, 0)
     
    -- create a simple model at the startPosition
    local model = Instance.new("Model", game.Workspace)
     
    local part1 = Instance.new("Part")
    part1.Size = Vector3.new(4, 4, 4)
    part1.Position = startPosition
    part1.Anchored = true
    part1.BrickColor = BrickColor.new("Bright yellow")
    part1.Parent = model
     
    local part2 = Instance.new("Part")
    part2.Size = Vector3.new(2, 2, 2)
    part2.Position = startPosition + Vector3.new(0, 3, 0)
    part2.Anchored = true
    part2.BrickColor = BrickColor.new("Bright blue")
    part2.Parent = model
     
    -- set the primary part
    model.PrimaryPart = part1
    model.Parent = game.Workspace
     
    -- create an obstruction at the endPosition
    local obstruction = Instance.new("Part")
    obstruction.Name = "Obstruction"
    obstruction.Size = Vector3.new(10, 10, 10)
    obstruction.Position = Vector3.new(0, 10, 0)
    obstruction.Anchored = true
    obstruction.BrickColor = BrickColor.new("Bright green")
    obstruction.Parent = game.Workspace
     
    wait(3)
    -- attempt to move the model to the obstructed endPosition
    model:MoveTo(endPosition)
    

    只需在网上搜索“Roblox 移动对象”即可获得https://developer.roblox.com/en-us/articles/positioning-objects,这是我的首选。因此,如果您问自己如何在 Roblox 中移动对象,这可能是一个不错的起点。

    【讨论】:

      【解决方案3】:

      如果您希望它是一个流畅的动画移动,只需在部件中添加一个BodyPosition,然后在脚本中将Position 设置为玩家的位置:

      Money.BodyPosition.Position = pl.Character.HumanoidRootPart.Position
      

      【讨论】:

        【解决方案4】:

        我建议以玩家为目标对项目进行补间

        补间的样子:

        local TweenService = game:GetService("TweenService")
        local part = script.Parent
        
        local Info = TweenInfo.new(
            5,           --seconds it takes to complete loop
            Enum.EasingStyle.Linear,     --easingstyle (how it moves)
            Enum.EasingDirection.InOut,    --easingdirection (which direction)
            -1,                    --times repeated (-1 = infinite)
            true,                 --reverse
            0                      --delay time
        )
         
        
        local Goals ={ --these are the goals of the tween
        Position = game.Workspace.Baseplate.Position
        }
        
         
        
        local tween = TweenService:Create(part,Info,Goals)
        tween:Play()
        

        【讨论】:

          猜你喜欢
          • 2017-06-15
          • 2020-05-07
          • 2021-12-30
          • 1970-01-01
          • 1970-01-01
          • 2015-06-01
          • 2011-05-27
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多