Problem about egg hatching animation (about math)

so here is what i’m trying to accomplish;
https://gyazo.com/0f999cc4c20243a0c8d9a55f3b1d50b0

i have a hatch time which decides when the hatch will be completed etc, i need that effect to be done in that time

let me send my current code;

(The Problem is the “ActualWait” variable in the script)

		for i = 1, AmountOfHits do
			local normalizedIndex = i / AmountOfHits
			local ActualWait 
			local HitDirection
			
			local Directions = {
				["Right"] = -1,
				["Left"] = 1
			}
			
			if LastHitDirection == "Right" then
				HitDirection = "Left"
			else
				HitDirection = "Right"
			end
			
           -- THE ACTUAL PROBLEM, WHICH NEEDS TO BE CHANGED
			ActualWait = HatchTime * math.exp(-i / 4)
			
			local Force = math.abs((i - AmountOfHits) * 1.8) * Directions[HitDirection]
			local WantedValue = CFrame.Angles(0,0, math.rad(Force))
			
			
			TS:Create(newCFrame, TweenInfo.new(ActualWait), {Value = WantedValue}):Play()
			
			local WantedScale = i  / 92
			if i < (AmountOfHits  / 2) then
				
				TS:Create(ScaleNumber, TweenInfo.new(ActualWait / 1.5, Enum.EasingStyle.Back), {Value =  WantedScale + ScaleNumber.Value}):Play()
			else
				-- dont rlly mind this part
				ScaleCompleted = true
				TS:Create(ScaleNumber, TweenInfo.new(ActualWait, Enum.EasingStyle.Linear), {Value = 0.1}):Play()
			end
			
			
			LastHitDirection = HitDirection
			wait(ActualWait)
		end
		
	Completed = true		
		
	end)

So the first thing is that if hatch time is like 2 then this takes 10 seconds to accomplish
and so yeah, i’d appreciate it if someone could provide some useful math formula or something for this

Couldn’t you just do HatchTime * 5?

1 Like