嗨,最近我在我的 roblox 游戏中为 m4a1 制作了一个视图模型,但是当我完成代码时它不起作用。我已经检查了多次,如果有人能发现错误,我将不胜感激:)
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local camera = game.Workspace.CurrentCamera
local framework = {
inventory = {
"M4A1";
"M9";
"KNIFE";
"FRAG";
};
module = nil;
viewmodel = nil;
}
function loadSlot(Item)
local viewmodelFolder = game.ReplicatedStorage.Viewmodels
local moduleFolder = game.ReplicatedStorage.Modules
if moduleFolder:FindFirstChild("Item") then
framework.module = require(moduleFolder:FindFirstChild(Item))
if viewmodelFolder:FindFirstChild("Item") then
framework.viewmodel = viewmodelFolder:FindFirstChild(Item):Clone()
framework.viewmodel.Parent = camera
end
end
end
RunService.RenderStepped:Connect(function()
for i, v in pairs(camera:GetChildren()) do
if v:IsA("Model")then
v:SetPrimaryPartCFrame(camera.CFrame)
end
end
end)
loadSlot(framework.inventory[1])
试试这个,我重新做了一点,应该可以用
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local camera = game.Workspace.CurrentCamera
local framework = {
inventory = {
"M4A1",
"A",
"B",
"C",
},
module = nil,
viewmodel = nil,
}
function loadSlot(Item)
local viewmodelFolder = game.ReplicatedStorage.Viewmodels
local moduleFolder = game.ReplicatedStorage.Modules
if moduleFolder:FindFirstChild(Item) then
framework.module = require(moduleFolder:FindFirstChild(Item))
if viewmodelFolder:FindFirstChild(Item) then
framework.viewmodel = viewmodelFolder:FindFirstChild(Item):Clone()
framework.viewmodel.Parent = camera
end
end
end
RunService.RenderStepped:Connect(function()
for i, v in pairs(camera:GetChildren()) do
if v:IsA("Model") then
v:SetPrimaryPartCFrame(camera.CFrame)
end
end
end)
loadSlot(framework.inventory[1])
也许尝试在你的枪前面创建一个点(旋转点),将枪锚定到该点,然后像主要零件一样设置该点并使用 Cframe:FromAngularAnglesXYZ 旋转它。