0 votes

I am trying to make a mesh that starts off as a colour and fades to black as damage is applied.

Is their any capability to do this?

in Engine by (52 points)

1 Answer

0 votes

You should be able to do that by modifying its material's diffuse color. If your mesh is not too complicated, you can create a new material override (in MeshInstance) and modify the diffuse color of this one only, so it won't affect other instances of the same mesh.

by (28,835 points)

This is what I have so far

var mesh = meshNode.get_mesh(); 
var mat = mesh.surface_get_material(0);     
mat.diffuse = 0;    
mesh.surface_set_material(0, mat);

But mat is returning null.

This is what I have for the editor.

enter image description here

You can apply a material override in the inspector, or using the following code:

# Create a new FixedMaterial (for example)
var new_material = FixedMaterial.new()

# Assign it on the mesh as an override
mesh_instance.set_material_override(new_material)

# Modify the material (it will be applied on all meshes you use it on, here only one)
# Note: if you need a texture or other setup, you may want to set more params
new_material.set_parameter(Material.PARAM_DIFFUSE, Color(0,1,0))
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.