Hello! I am making a ghost hunting game and I want the tool to stay with the camera rotation, for example, if I’m looking up I want the tool to be at the bottom right of the camera. (also it would be nice for the tool to look at the camera)
Here is a video demonstrating the issue:
I haven’t tried anything yet, because I couldn’t find anything. (If video doesn’t work right-click and click on “Open audio in New Tab”. It will download the video for you)
like a viewmodel? If you want to create one of those (which are usually just a pair of fake arms used in FPS games), you can apply the viewmodel to the camera’s CFrame, like so:
-- Code like this are ran on the Client and are ran using RunService.RenderStepped
local Camera = workspace.CurrentCamera -- the Players Camera
local Offset = CFrame.new(0,0,0) -- an Offset from the Camera's CFrame
Model:PivotTo(Camera.CFrame * Offset) -- Pivots using the corresponding Data
Hhowever if you are going to move the Motor6D, it would ne more complicated.
I see what you mean but how can I attach the items to the viewmodel? Like right now, I made a part called “ViewmodelTest” and got it placed in front of the player:
One question, the other players’ view of the item looks way messed up.
On the other screens the tool is like way up in the air or in the ground. How can I fix this?
local players = game:GetService("Players")
local runService = game:GetService("RunService")
local player = players.LocalPlayer
local currentGrip
local baseCF
local tool
local character
player.CharacterAdded:Connect(function(c)
character = c
local RightHand = character:WaitForChild('RightHand',1)
assert(RightHand, 'Character failed to load.')
RightHand.ChildAdded:Connect(function(child)
if child:IsA("Weld") and child.Name == "RightGrip" then
baseCF = child.C0
local newGrip = child:Clone()
newGrip.Parent = child
--child.Enabled = false
currentGrip = newGrip
end
end)
character.ChildAdded:Connect(function(child)
if child:IsA("Tool") then
tool = child
end
end)
end)
function lerp(a, b, t)
return a + (b - a) * t
end
local avgdt = 1/60
local offsetCF = CFrame.new(1, -1, -2)
local xz = Vector3.new(1,0,1)
local vel = 0
local bobCF1 = CFrame.identity
local bobCF2 = CFrame.identity
runService.RenderStepped:Connect(function(dt)
if currentGrip then
local vel2 = (character.PrimaryPart.AssemblyLinearVelocity*xz).Magnitude
vel = lerp(vel, vel2, avgdt)
local bobT = time()*(vel2/2)
local bob2 = math.cos(bobT)*vel/60
local bob1 = math.sin(bobT)*vel/360
local bob3 = bob2*bob1
bobCF1 = bobCF1:Lerp(CFrame.Angles(bob3, bob1, bob3),avgdt*10)
bobCF2 = bobCF2:Lerp(CFrame.Angles(bob3, bob3, 0),avgdt*10)
currentGrip.C0 = currentGrip.Part0.CFrame:ToObjectSpace(workspace.CurrentCamera.CFrame)-- * baseCF
* bobCF1 * offsetCF * bobCF2
avgdt = lerp(avgdt, dt, .01)
end
end)
This one will clone the grip and the original one will be the only one that replicates.