I’m making a 3D health bar and I need help trying to figure out the formula for the offset position of this part. This is because, whenever I tween the size, both negative and positive sides on that axis (normalId’s) go inward when the tween is lower, and outward when the tween is higher.
I want to make it so that it looks like only one side is going up by tweening it the same way while also changing its position at the same time. But I need help finding a formula for this, and that’s what I can’t find.
I’ve got the tweening size part down, but how can I find the formula for the part that I’m tweening?
The Current Dimensions of the Green Bar is {10, 0.5, 1.5}
,
The Current Position of the Green Bar is {-44, 0.75, 33.5}
Script:
local player = game.Players.LocalPlayer
local viewport = script.Parent
local character = player.Character or player.CharacterAdded:Wait()
local GreenBar = viewport:WaitForChild("Health_Green")
local cam = Instance.new("Camera")
viewport.CurrentCamera = cam
cam.Parent = viewport
cam.CFrame = CFrame.new(Vector3.new(-24.672, 1.154, 38.232)) * CFrame.Angles(math.rad(2.702), math.rad(-16.649), math.rad(-0))
character:WaitForChild("Humanoid").HealthChanged:Connect(function()
local sizeX = (character:WaitForChild("Humanoid").Health / character:WaitForChild("Humanoid").MaxHealth) * 10
local tween = game:GetService("TweenService"):Create(GreenBar, TweenInfo.new(.25, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0), {
Size = Vector3.new(sizeX, GreenBar.Size.Y, GreenBar.Size.Z)
})
local posX = 1 -- will be changed after I find the formula.
local posTween = game:GetService("TweenService"):Create(GreenBar, TweenInfo.new(.25, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0), {
Position = Vector3.new(posX, GreenBar.Position.Y, GreenBar.Position.Z)
})
tween:Play()
posTween:Play()
end)