Help with calculating the rotation of a frame

I want the frame to shake more agressively the lower the players hp is, the max degrees should be 5.625 but im terrible at maths

local frame = script.Parent
local tween = game:GetService("TweenService")
local hum = game:GetService("Players").LocalPlayer.Character:WaitForChild("Humanoid")

local function jiggle()
	local rot = --idk
	tween:Create(frame, TweenInfo.new(.25, Enum.EasingStyle.Quad), {Rotation = math.random(-rot, rot)}):Play()
end

game:GetService("RunService"):BindToRenderStep("jiggle", 200, jiggle)

You could normalise the health to a 0-1 range using the formula (x - xMin)/(xMax - xMin), subtract the result from 1 (to get a reversed value, so that shaking increases as the value lowers), and then multiply that by the maximum rotation.
Therefore, at 10% health, the frame shakes at 90% of the maximum rotation, and vice versa.

like this?

local hp = (hum.Health - hum.MaxHealth)/(hum.MaxHealth - 0)
local rot = hp-1 * 5.625

EDIT: it gave me the error RunService:fireRenderStepEarlyFunctions unexpected error while invoking callback: Players.TheWhat603.PlayerGui.PlayerStats.Frame.HealthbarFrame.HealthBar.LocalScript:8: invalid argument #2 to 'random' (interval is empty) so prolly not

Sorry for not responding.
The equation in your case would be

local normalisedHp = hum.Health/hum.MaxHealth
local rot = (1-normalisedHp) * 5.625

(you can skip half the equation because it starts from 0)

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.