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

Third person shooter script, turns whole player how do i make just the upperTorso turn?

Asked by 6 years ago

I found this Third person shooter script that allows the character to aim like in third person. It works with r6 and r15 i am using r15. I am trying to modify it so the UpperTorso turns. It is currently turning the whole player, how do i add a line of code were instead of the whole player turning in the direction of the cross hair, just the UpperTorso. this is the script im trying to modify.

wait() --game.StarterGui:SetCoreGuiEnabled(3, false)

local Players = game:GetService('Players') local UserInputService = game:GetService('UserInputService') local RunService = game:GetService('RunService')

local v3n = Vector3.new local cfn, cfa = CFrame.new, CFrame.Angles local rn = Ray.new local min, max, rad, huge, atan2 = math.min, math.max, math.rad, math.huge, math.atan2

local cam = workspace.CurrentCamera cam.CameraType = 'Scriptable'

UserInputService.MouseBehavior = 'LockCenter' UserInputService.MouseIconEnabled = false

local function clamp(v, v0, v1) return (max( min( v1, v ), v0 ) ) end

local function wrap(v, v0, v1) v = v % (v1 - v0) return (v0 + v) end

local mDelta = v3n(0, 0, 0) local yaw = 0 local pitch = 0 local minZoom = 70 local maxZoom = 40 local regularSensitivityX = 50 local zoomSensitivityX = 25 local regularSensitivityY = 50 local zoomSensitivityY = 25 local currentSensitivityX = regularSensitivityX local currentSensitivityY = regularSensitivityY

local function mUpdate(mouse) mDelta = mouse.Delta yaw = wrap(yaw + mDelta.X / (100 / currentSensitivityX), 0, 360) pitch = clamp(pitch - mDelta.Y / (100 / currentSensitivityY), -80, 80) end

local LocalPlayer = Players.LocalPlayer local Character = LocalPlayer.Character local characterChildren = Character:GetChildren() local Humanoid = Character.Humanoid local HRP = Character.HumanoidRootPart

local Status = Humanoid.Status

Humanoid:AddCustomStatus('Aiming') Humanoid:AddCustomStatus('Zooming')

local Aiming = Status.Aiming local Zooming = Status.Zooming

local function updateChildren() characterChildren = Character:GetChildren() end

Character.DescendantAdded:connect(updateChildren)

local function cUpdate() local origin = HRP.Position + v3n(0, 2, 0) local offset = v3n(2, 0, 6) local finalcf = cfn(origin) * cfa (0, -math.rad(yaw), 0) * cfa(math.rad(pitch), 0, 0) * cfn(offset) local finalpos = finalcf.p

local checkRay = rn(origin, (finalpos - origin).unit * offset.magnitude)

local hit, pos = workspace:FindPartOnRayWithIgnoreList(checkRay, characterChildren)

if not hit then
    cam.CoordinateFrame = finalcf
else
    local dist = (pos - origin).magnitude
    cam.CoordinateFrame = cfn(origin) * cfa (0, -math.rad(yaw), 0) * cfa(math.rad(pitch), 0, 0) * cfn(offset * (dist - 0.2)/(offset.magnitude) )
end
--cam.CoordinateFrame = 

end

local button1Down = false local button2Down = false

local function aUpdate(mouse)
if mouse.UserInputType == Enum.UserInputType.MouseButton1 then if mouse.UserInputState == Enum.UserInputState.Begin then button1Down = true elseif mouse.UserInputState == Enum.UserInputState.End then button1Down = false end end

if mouse.UserInputType == Enum.UserInputType.MouseButton2 then
    if mouse.UserInputState == Enum.UserInputState.Begin then
        button2Down = true
    elseif mouse.UserInputState == Enum.UserInputState.End then
        button2Down = false
    end
end

if button1Down or button2Down then
    Aiming.Value = true
else
    Aiming.Value = false
end

if button2Down then
    Zooming.Value = true
else
    Zooming.Value = false
end

end

local bdg = Instance.new("BodyGyro", HRP) bdg.maxTorque = v3n(0, 0, 0) bdg.P = 1000 bdg.D = 50

local function aim(isAiming) if isAiming then bdg.maxTorque = v3n(huge, huge, huge) spawn( function() while isAiming do bdg.cframe = cfn(HRP.Position, HRP.Position + v3n(cam.CoordinateFrame.lookVector.X, 0, cam.CoordinateFrame.lookVector.Z) ) wait() end end) Humanoid.AutoRotate = false else bdg.maxTorque = v3n(0, 0, 0) Humanoid.AutoRotate = true end end

local function zoom(isZooming) if isZooming then cam.FieldOfView = 40 currentSensitivityX = zoomSensitivityX currentSensitivityY = zoomSensitivityY else cam.FieldOfView = 70 currentSensitivityX = regularSensitivityX currentSensitivityY = regularSensitivityY end end

local mouse = UserInputService.InputChanged:connect(mUpdate) local camera = RunService.RenderStepped:connect(cUpdate)

local aiming1 = UserInputService.InputBegan:connect(aUpdate) local aiming0 = UserInputService.InputEnded:connect(aUpdate) local aiming = Aiming.Changed:connect(aim)

local zooming = Zooming.Changed:connect(zoom)

game:GetService("ControllerService").Instance:BindButton(8, "win! aaa")

print("Camera script ended")

Answer this question