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

Gun won't point right...?

Asked by
RCXI 0
9 years ago
local camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local character = player.Character
local torso = character:WaitForChild("Torso")

while true do
    local deltaTime = game:GetService("RunService").RenderStepped:wait()

    local aim = 1

    if character.BulletTime.Value or character.EnemyBulletTime.Value then
        aim = 0.5
    end

    local headDirection = torso.CFrame:vectorToObjectSpace(camera.CoordinateFrame.lookVector)
    headDirection = Vector3.new(math.abs(headDirection.X) / headDirection.X * math.min(math.abs(headDirection.X), 0.5), math.abs(headDirection.Y) / headDirection.Y * math.min(math.abs(headDirection.Y), 0.6), math.min(-0.2, headDirection.Z))
    local neckPosition = (torso.CFrame * torso.Neck.C0).p
    local neckCFrame = CFrame.new(neckPosition, neckPosition + torso.CFrame:vectorToWorldSpace(headDirection))
    torso.Neck.C0 = torso.Neck.C0:lerp(torso.CFrame:toObjectSpace(neckCFrame), deltaTime * 5 * aim)

    local shoulderPosition = (torso.CFrame * torso["Right Shoulder"].C0).p
    local shoulderDirection = torso.CFrame:vectorToObjectSpace(CFrame.new(shoulderPosition, mouse.Hit.p).lookVector)
    shoulderDirection = Vector3.new(shoulderDirection.X, shoulderDirection.Y, math.min(-0.2, shoulderDirection.Z))
    local shoulderCFrame = CFrame.new(shoulderPosition, shoulderPosition + torso.CFrame:vectorToWorldSpace(shoulderDirection))
    torso["Right Shoulder"].C0 = torso["Right Shoulder"].C0:lerp(torso.CFrame:toObjectSpace(shoulderCFrame), deltaTime * 8 * aim)

    if character.BulletTime.Value then
        torso.BodyGyro.CFrame = camera.CoordinateFrame
    end
end

Answer this question