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

Lerp to camera on x and z, snap to camera on y?

Asked by 7 years ago

I know the title isn't too straight forward. what I mean is like

I'm creating an FPS game, and I want it so that the arms lerp on the x, and z axis of the camera, but on the y axis, it snaps to the camera's y axis. I've been experimenting, but it never appears where I want it to go. Here's my code so far:

warn("Engine started")
getrawmetatable = getrawmetatable
local camera = workspace.CurrentCamera 
local player = game:service'Players'.LocalPlayer
local mouse = player:GetMouse()
local replicatedstorage = game:service'ReplicatedStorage'

local larm = replicatedstorage.LeftArm:Clone()
local rarm = replicatedstorage.RightArm:Clone()
local smg = replicatedstorage.SMG:Clone()

larm.Parent = camera
rarm.Parent = camera
smg.Parent = camera
local CurrentAnimation = "Idle"

local Lerp = larm.CFrame:lerp(camera.CFrame*CFrame.new(-2,-1,1)*CFrame.Angles(math.rad(90),0,0),.5)
mouse.Move:connect(function()
    local x,y,z,R00,R01,R02,R10,R11,R12,R20,R21,R22 = camera.CFrame:components()
    Lerp = larm.CFrame:lerp(CFrame.new(x,0,z,R00,R01,R02,R10,R11,R12,R20,R21,R22)*CFrame.new(-2,-1,1)*CFrame.Angles(math.rad(90),0,0),.5)
end)
game:service'RunService'.RenderStepped:connect(function()
    larm.CFrame = Lerp * CFrame.new(0,camera.CFrame.y,0)
end)

while wait() do -- Most level 7s have getrawmetatable in their environment, so if it detects it, gg.
    if getrawmetatable ~= nil then
        game:service'Players'.LocalPlayer:Kick("Level 7 (getrawmetatable)")
    end
end

This is in a localscript in StarterPlayerScripts

0
Nice to meet you here, Minty. fireboltofdeathalt 118 — 7y

Answer this question