Random "Tint" Of Game Object - Stopping Totally Black Color? (SOLVED)

Hi,

I have the following code:
go.set( "/Enemy#Enemy", "tint", vmath.vector4( math.random(0.1, 1), math.random(0.1, 1), math.random(0.1, 1), 1 ) )

Problem is I still occasionally get a totally black image?
How do I stop getting a totally black image?
Thanks!

Jesse

If the tint of the image gets (0.1, 0.1, 0.1), the it may appear black. Try this instead.:

        local red = math.random()
	local green = 0
	local blue = 0
	if red < 0.7 then
		local random = math.random()
		if random > 0.5 then
			green = math.random(0.5, 1)
			blue = math.random()
		else
			blue = math.random(0.5, 1)
			green = math.random()			
		end
	end

This should give you sufficiently good result

math.random returns integers when given a range so it’ll only give you 0 or 1 with your code. Try this instead:

math.random(1,10)/10

5 Likes

Didn’t know about this :thinking:(Should’ve read the manual more carefully) :

4 Likes

Ok, got it working, thanks!

2 Likes