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

Why does offsetting camera with math.rad not affect the Y and Z axis?

Asked by 4 years ago
local c = workspace.CurrentCamera
local p = game.Players.LocalPlayer

workspace.ChildAdded:Connect(function(Child)
    if Child:IsA("Explosion") then
        Shake()
    end
end)


function Shake()
for i = 1, 20 do
    wait()
local RandomizerX = math.random(-70,70) 
local RandomizerY = math.random(0,70)   
local RandomizerZ = math.random(-70,70) 
p.Character.Humanoid.CameraOffset = Vector3.new(math.rad(RandomizerX, 15, RandomizerZ))
end
p.Character.Humanoid.CameraOffset = Vector3.new(0,0,0)
end

It only changes the X axis, any fix?

0
math.rad takes 1 argument, not 3. The other 2 arguments are ignored. Vector3.new takes 3 arguments and you only have 1 when you call it at line 17. Also, CameraOffset is specified in studs, not angles. It only changes the X axis because the only argument you have in Vector3.new is the first one, which specifies the X axis (X, Y, Z) pidgey 548 — 4y

1 answer

Log in to vote
0
Answered by
DanzLua 2879 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

You reason the script isn't working is be you are giving Vector3.new() a single value as well as giving math.rad 3 values when it only accepts one.

To fix this simply wrap each value with its own math.rad

local c = workspace.CurrentCamera
local p = game.Players.LocalPlayer

workspace.ChildAdded:Connect(function(Child)
    if Child:IsA("Explosion") then
        Shake()
    end
end)


function Shake()
for i = 1, 20 do
    wait()
local RandomizerX = math.random(-70,70) 
local RandomizerY = math.random(0,70)   
local RandomizerZ = math.random(-70,70) 
p.Character.Humanoid.CameraOffset = Vector3.new(math.rad(RandomizerX), math.rad(15), math.rad(RandomizerZ))
end
p.Character.Humanoid.CameraOffset = Vector3.new(0,0,0)
end
Ad

Answer this question