Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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?

1 comment

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)

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.