I am trying to make a character for a fps game and I want the arms to follow the camera. However, whenever I run the animation in game, the arms move with the camera, except they move backwards?? It’s hard to explain so I’ll just show you
Roblox aim anim.wmv (75.3 KB)
Roblox game rec.wmv (864.4 KB)
Here’s some of the code:
local UserInputService = game:GetService(“UserInputService”)
local Players = game:GetService(“Players”)
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = game:GetService(“Workspace”).CurrentCamera
local humanoid = Character:WaitForChild(“Humanoid”)
local aimAnim = script:WaitForChild(“Aim”)
local aimTrack = humanoid.Animator:LoadAnimation(aimAnim)
– Function to update arms rotation
local function updateArmsRotation()
local lookVector = Camera.CFrame.LookVector
local lookAngle = lookVector.Y
local aimTimePos = (lookVector.Y + 1)/2 * aimTrack.Length
print(aimTimePos)
aimTrack:Play()
aimTrack.TimePosition = aimTimePos
aimTrack:AdjustSpeed(0)
end
game:GetService(“RunService”).RenderStepped:Connect(function()
updateArmsRotation()
end)
try this,
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = game:GetService("Workspace").CurrentCamera
local humanoid = Character:WaitForChild("Humanoid")
local aimAnim = script:WaitForChild("Aim")
local aimTrack = humanoid.Animator:LoadAnimation(aimAnim)
-- Function to update arms rotation
local function updateArmsRotation()
local lookVector = Camera.CFrame.LookVector
local aimTimePos = math.acos(lookVector.Y / (lookVector.magnitude)) / math.pi * 2 * aimTrack.Length
aimTrack:Play()
aimTrack.TimePosition = aimTimePos
aimTrack:AdjustSpeed(0)
end
game:GetService("RunService").RenderStepped:Connect(function()
updateArmsRotation()
end)
1 Like
Thank you for your help, however the issue wasn’t the scripting but rather how the character was rigged. Some parts such as the head, torso, humanoid root part, and all of the joints, were rotated 180 degrees. It would be useful to know what should be 180 degrees and what should be 0 degrees since intuitively it should make no difference if the camera is facing the correct direction?