【问题标题】:How to spawn a part at the current mouse position in Roblox Lua?如何在 Roblox Lua 中的当前鼠标位置生成零件?
【发布时间】:2018-09-14 13:25:04
【问题描述】:

我一直在为 Roblox 编写脚本。代码如下:

local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Activation = 
Instance.new("Sound",game.Players.LocalPlayer.Character.Head)
local char = Player.Character
local hum = char.Humanoid
local root = char.HumanoidRootPart

UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.F then
    Activation.SoundId = "rbxassetid://1581091676" --Plays Mangekyou Sharingan Activation Sound.
    Activation:Play()
    wait(0.3)       
    game.Players.LocalPlayer.Character.Head.face.Texture = "rbxassetid://76285632" --When F is pressed, face texture changes to sharingan decal.
    game:GetService("Chat"):Chat(Player.Character.Head, "Mangekyou Sharingan!")
end
end)

UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.R then
    Activation.SoundId = "rbxassetid://1580990602" --Plays Amaterasu Activation Sound.
    Activation:Play()
    game:GetService("Chat"):Chat(Player.Character.Head, "Amaterasu!")
    local Target = Instance.new("Part") --makes a part
    Target.Parent = game.Workspace
    Target.Position = Vector3.new(Mouse.target.Position) --makes the part spawn where the mouse is 
    Target.Transparency = 1 
    Target.Anchored = true 
    Target.CanCollide = false 

    local Amaterasu = Instance.new("Fire")
    Amaterasu.Parent = game.Workspace.Part
    Amaterasu.Color = Color3.new(0,0,0)
    Amaterasu.SecondaryColor = Color3.new(0,0,0) --amaterasu properties
    Amaterasu.Size = 25

    local R = Instance.new("RocketPropulsion") --rocket propulsion, parents amaterasu
    R.Parent = Amaterasu
    R.MaxThrust = 300
    R.ThrustP = 30
    R:Fire()
end
end)

UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.G then
    game.Players.LocalPlayer.Character.Head.face.Texture = "rbxassetid://22557247" --When G is pressed, face texture changes back to normal.(leaves face blank isnt working :/)
end
end)
-----------------------------

我需要帮助的是在游戏中鼠标的当前位置生成父级 amaterasu 射击的部分。我对Target.Position = Vector3.new(Mouse.target.Position)Target.Position = Vector3.new(Mouse.Hit)都进行了研究和尝试。

这两个都不起作用,最终结果是无论我的鼠标在游戏中的哪个位置,都会在底板中间产生部分。

【问题讨论】:

    标签: lua roblox


    【解决方案1】:

    我们需要的是CFrame。所以我们会这样做:

    Target.CFrame = CFrame.new(Mouse.target.Position)
    

    【讨论】:

      【解决方案2】:

      这是票

      local Part = Instance.new("Part",game.Workspace);
      Part.CFrame = Mouse.Hit;
      

      【讨论】:

        猜你喜欢
        • 2022-08-19
        • 2016-04-10
        • 1970-01-01
        • 2017-08-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多