Trying to change the color of children based on rotation instead changes the entire parent

Godot Version

4.6.1

Question

basically i’m trying to do this to my cabal of planemeshes:

but instead my code does this:

the code in question:

func  _process(delta: float) -> void:
	for p in get_children():
		var ry = rad_to_deg(p.global_rotation.y)
		var rx = rad_to_deg(p.global_rotation.x)
		var darkening = 0.0
		if ry>150 or rx>150:
			darkening = 0.4
		elif ry>100 or rx>100:
			darkening = 0.2
		p.get_active_material(0).emission = colors[p.color_id].darkened(darkening)
		

^the cabal in question

code of the root CollectibleDiamond node:

extends Area3D
@export var type : Globals.collectible_types = Globals.collectible_types["DIAMOND"]
@export var id : int = 0

func _ready() -> void:
	if type == Globals.collectible_types["DIAMOND"] and ProgressTracker.diamond_list[id]==true:
		queue_free()

func _process(delta: float) -> void:
	$Model.rotation.y+=1.7*delta

They all likely share the same material resource.

1 Like

thank you, i completely forgot about that. for the sake of anyone who might have this ultraspecific problem again in the future: i also changed the code of the “model“ node a little bit to solve an issue where the color would change as it rotated:

extends Node3D
@export var colors : Array[Color]

func _ready() -> void:
	for p in get_children():
		p.get_active_material(0).emission_enabled=true

func  _process(delta: float) -> void:
	for p in get_children():
		var ry = rad_to_deg(p.rotation.y)
		var rx = rad_to_deg(p.rotation.x)
		var darkening = 0.0
		if ry>50 or rx>50:
			darkening = 0.4
		elif ry>30 or rx>30:
			darkening = 0.2
		p.get_active_material(0).emission = colors[p.color_id].darkened(darkening)
		

granted this does mean i won’t be able to emulate directional lighting, but eh, maybe i’ll figure that out another time.