Here's an example of changing the color of an object that passes through a Trigger using different methods:
function Trigger:onEnter(obj)
obj.color = rgba("#FF0000") -- hex value
obj.color = rgba(0,255,0) -- 3 or 4 values for r,g,b,a [0,255]
obj.color = hsb(60,1,1) -- 3 values for hue [0,360], saturation [0,1], and brightness [0, +]
end
Here's an example of making an object brighter based on its velocity when it goes through a Trigger:
function Trigger:onEnter(obj)
obj.color = obj.color * obj:getRigidBody():getLinearVelocity():length()
end
Note that we assume the object's material gets its color from the object's color property. This can differ depending on the material. See this article for more information on object color.
If we wanted to change the object's material color, we could do so like this:
function Trigger:onEnter(obj)
mat = obj:getMeshModel():getMaterialTable():getDefaultMaterial()
mat:getDiffuse().color = rgba(0,255,0)
end
Or make an object's material translucent:
function Trigger:onEnter(obj)
mat = obj:getMeshModel():getMaterialTable():getDefaultMaterial()
mat:getTranslucency().blendMode = "AlphaBlended"
mat:getTranslucency().opacity = 0.5
end
Note that when we change an object's material properties like in the preceding two examples, all objects that use same material will be affected.
Comments
0 comments
Please sign in to leave a comment.