Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I make the arms face the way the camera is looking?

Asked by 6 years ago

I've got my viewmodel working and all, but Its only facing one direction- It doesn't change when I face another direction. How would I do that? This is what I have currently:


local clone = game.Workspace.AWP:Clone() clone.Parent = game.Workspace game:GetService("RunService").RenderStepped:connect(function() print("ok") clone:SetPrimaryPartCFrame(CFrame.new(game.Workspace.Camera.CoordinateFrame.Position)) end)

and yes I have tried googling before coming here.

Thanks in advance.

0
Connect not connect User#19524 175 — 6y
0
On line 3, what you wrote may work in studio but could not work in a real game because camera is local to one player not the server. OBenjOne 190 — 6y
0
You should probably get camera from a player OBenjOne 190 — 6y

2 answers

Log in to vote
1
Answered by 6 years ago
 clone:SetPrimaryPartCFrame(CFrame.new(game.Workspace.Camera.CoordinateFrame))

The problem with this is it makes a new cframe (with default rotation) and simply sets it's position to that of the camera. Instead, try:

 clone:SetPrimaryPartCFrame(game.Workspace.Camera.CoordinateFrame)

However there's still an issue with this. This will only work in studio testing. Instead, I would simply do either of these..

If you wish for client side viewmodel with no one else seeing it, do this in a local script placed in StarterPlayerScripts.

local player = script.Parent.Parent
player.CharacterAdded:Connect(function(char) --detects when spawning each time
    local camera = game.Workspace.CurrentCamera
    local clone = game.Workspace.AWP:Clone() --Makes clone
    clone.Parent = game.Workspace
    game:GetService("RunService").RenderStepped:Connect(function()
        if clone then
            clone:SetPrimaryPartCFrame(game.Workspace.Camera.CoordinateFrame)
        end
    end)
end)
Ad
Log in to vote
0
Answered by
OBenjOne 190
6 years ago
Edited 6 years ago

The reason that your viewmodel only points one direction is that you only change it's direction once. Add a loop on line 13:

while true do wait ()
clone:SetPrimaryPartCFrame(CFrame.new(game.Workspace.Camera.CoordinateFrame.Position))
end

This may work in studio, but in a real game camera cannot be accessed from the server.

EDIT: this won't fix all your problems because filtering enabled. Plus, a ROBLOX game works differently than a studio test in that it is multi player. I don't know what that would do to getting camera from workspace

Answer this question