現在、Roblox のPointLightオブジェクトのメソッドを作成しています。Brightness
現在、私は PointLight のプロパティを増減するメソッドを作成していますが、必要な数式を取得しようとして壁にぶつかりました。
プログラムは、DarkenSpeed (2 秒) のスパンで Brightness (1) から FadedBrightness (.3) までループする必要があります。考えられる解決策をグーグルで調べてみましたが、探しているものが具体的すぎるのではないかと心配しています。
コード スニペットを次に示します。
local LightSource = {
-- The value the PointLight's Brightness property will be when night and day,
-- respectively.
Brightness = 1,
FadedBrightness = .3,
-- How long (in seconds) it takes for the light source's brightness to be
-- faded in/out.
BrightenSpeed = 2,
DarkenSpeed = 2
}
-- There is an IncreaseBrightness method, but that should be easy enough to
-- modify once the below is working.
function LightSource:DecreaseBrightness()
-- self.Light refers to the PointLight instance.
-- light.Brightness would be the current `Brightness` property.
local light = self.Light
-- Need to combine Brightness, FadedBrightness and DarkenSpeed into a formula
-- for decrementing.
local decrement = self.FadedBrightness / (self.Brightness * self.DarkenSpeed) -- 0.15, that won't work at all.
while light.Brightness >= self.FadedBrightness do
light.Brightness = light.Brightness - decrement
wait()
end
end
これを達成するためのより良い方法、または別の方法があれば、私はすべて耳にします。私は自分のコードでトンネル ビジョンを取得する傾向があり、現在の問題以外は何も考えていません。