Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do you make something fade, from a color to another color?

Asked by 11 years ago

How do you make something fade, from a color to another color? Like, when you touch a brick, it turns from "Black", to "Red", how would you do that? You would have to use the "Touched" event correct? But I am kind of confused, I never tried this I'm just having trouble of thinking of what I'd do. Could someone demonstrate me, by giving out an example? It'd be a function correct?

1 answer

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
11 years ago

@haillin's answer fades the part out (transparent) and then changes the color, which I don't think is the question you are asking?

Unfortunately, ROBLOX doesn't allow you to have continuous colors for the BrickColor of a Part. Only the set palette of BrickColors can be used.

Luckily, they do allow this to be done with SpecialMesh's.

Here is how you could make the part fade, which you could do on Touched. Most likely, you should remember to make some sort of debounce system so it will not start fading again until it finishes. This snippet includes that.

I assume the Script is parented to the Part in question, and that it has a SpecialMesh called Mesh using the following mesh:

http://www.roblox.com/Mini-Brick-item?id=9857022

and with a Texture of solid white (just search through free decals).

01local fading = false;
02 
03script.Parent.Mesh.Scale = script.Parent.Size * 2;
04 
05function touched()
06    if fading then
07        -- We will not start fading again
08        -- until the first fade finishes
09        return;
10    end
11    fading = true;
12    local black = Vector3.new(0,0,0);
13    local red= Vector3.new(0,0,1);
14    -- VertexColor has same values as a Color3,
15    -- but it's stored as a Vector3
View all 28 lines...

This solution has other limitations, unfortunately. If you use a mesh, you won't be able to see the material of a part, or any of its surfaces. It also won't have outlines.

EDIT: A more modular approach

Thinking on this, there's a much cleaner way to manage fading. We can make ourselves a fade function which lets us use this in more contexts than just the touched event in a clean way.

01function fade(part,from,to,time)
02    time = time or 1; -- Default to 1 second
03    for i = 0, 1, 1/(time/.03) do
04        local col = from * (1-i) + to * i;
05        part.Mesh.VertexColor = col;
06        wait(0.03);
07    end
08end
09 
10local fading = false;
11function touched(h)
12    if fading then
13        return;
14    end
15    -- We can also check for things like
View all 21 lines...
0
Roblox now made it a feature! Nickoakz 231 — 8y
Ad

Answer this question