Effects Intensity Based on Exponential Scales

Hello, I’m trying to make an effect that gets more intense the closer you are to a part.
I have a few parameters set to make the effect begin at a low level and gradually scale up to another level of intensity based on the distance (Magnitude)

This is my code:
(Placeholder for testing)

local Player = game.Players.LocalPlayer
local Character = Player.CharacterAdded:Wait()
local HRP = Character:WaitForChild("HumanoidRootPart")
local Part = workspace:WaitForChild("Part")
local RunService = game:GetService("RunService")

local MaxDistance = 20
local MinDistance = 5

RunService.Heartbeat:Connect(function(t)
	local Intensity = (math.clamp((HRP.Position-Part.Position).Magnitude,MinDistance,MaxDistance)-MinDistance) / (MaxDistance-MinDistance)
	print(1-Intensity)
end)

What I want it to do is scale the Intensity value on an exponential graph, like the following example shown in this video (at timestamp 0:58):

1 Like

Take a look at TweenService | Roblox Creator Documentation

I get what you mean by using TweenService, but it’s not what I’m referring to. I want the Intensity to scale up exponentially from MinDistance to MaxDistance.

I forgot to mention, this is what my code does.

Yep so you would do

local EASING_STYLE = Enum.EasingStyle.Quad
local EASING_DIRECTION = Enum.EasingDirection.Out

RunService.Heartbeat:Connect(function(t)
	local Intensity = (math.clamp((HRP.Position-Part.Position).Magnitude,MinDistance,MaxDistance)-MinDistance) / (MaxDistance-MinDistance)

    local tweenedValue = TweenService:GetValue((1-Intensity), EASING_STYLE, EASING_DIRECTION)
	print(1-Intensity, "->", tweenedValue)
end)

Use https://easings.net/ for reference

It works!! I didn’t know that was a function of TweenService but it’s very useful, so thanks for your help :+1:

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