My intention is to make the player’s camera shake a bit. The script below:
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
while true do
for i = 1, 20 do
wait()
char.Humanoid.CameraOffset = Vector3.new(math.random(-0.5, 0.5),math.random(-0.5, 0.5),math.random(-0.5, 0.5))
end
char.Humanoid.CameraOffset = Vector3.new(0,0,0)
wait(math.random(0, 3))
end
doesn’t work unless the XYZ axes are integers. However, integers are a bit too much for the gentle camera shake. Please help.
math.floor rounds a number down to the integer below it. For example, 1.2 would go to 1, 5.9 would go to 5. I am wondering, why can’t you use decimals?
Actually, is there an error inside the error output? In other cases, if that isn’t supposed to be happening for you read all the stuff in the knowledge of ROBLOX programming codes, you should probably post it in engine bugs where decimals don’t work.
Edit: Nevermind, i just read the post where you said there’s no errors.
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
function GetOffset(a)
return (math.random(1, a * 1000) / 1000) - a / 2
end
while true do
local hum = char:WaitForChild("Humanoid")
for i = 1, 20 do
local function GetShake()
return (1 - math.abs(10 - i) / 10) * GetOffset(0.5)
end
wait()
hum.CameraOffset = Vector3.new(GetShake(),GetShake(),GetShake())
end
hum.CameraOffset = Vector3.new(0,0,0)
wait(math.random(0, 3))
end
I spiced things up with some math, which intensifies the shaking and then slows it down in each loop. I can attest that this works, with decimals, as I have tested it myself in studio.