So, there is a game called entrenched, and they made that when aiming the camera is moved to a rifle, rather than rifle to the camera, also when you walk or rotate it’s in-line with camera
I want to recreate this effect, but after some tries it’s not following the camera, this is how it looks:
Code for aiming (test code)
local anim: AnimationTrack
local camera = workspace.CurrentCamera
local isEquipped = false
local plr = game.Players.LocalPlayer
script.Parent.Equipped:Connect(function()
local char = plr.Character
if not char:IsA("Model") then
return
end
if not anim then
anim = char.Humanoid.Animator:LoadAnimation(script.Parent.Animation)
end
anim:Play()
end)
script.Parent.Unequipped:Connect(function()
isEquipped = false
if anim then
anim:Stop()
end
end)
game.UserInputService.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.E then
isEquipped = not isEquipped
while isEquipped do
local relative = plr.Character.Head.CFrame:toObjectSpace(script.Parent.Aim.CFrame)
plr.Character.Humanoid.CameraOffset = relative.Position
task.wait(0)
end
plr.Character.Humanoid.CameraOffset = Vector3.zero
end
end)
and auto-rotate
local char = script.Parent
while true do
local X,Y,Z = workspace.CurrentCamera.CFrame:ToOrientation()
local CF = CFrame.Angles(0, Y, 0)
char:PivotTo(CFrame.new(char.PrimaryPart.CFrame.Position) * CF)
workspace.CurrentCamera.CFrame *= CFrame.new(char.Head.CFrame.Position)
* CFrame.new(0,0,5)
task.wait(0)
end
Does anyone have solution?