Godot Ambient Lightning in GDScript-

Godot Version



I want to start by saying I am relatively new to godot, so there may just be some basics I don’t understand and can’t seem to find the right information on.
I took a look around and watched a few videos and none of the results gave me the answer I was looking for.

I have a DirectionalLight3D node and a WorldEnvironment node contained within a Parent Node3D. The Parent Node3D has the script attatched and is where all the following code is stored.

var display_time = 0

# Called when the node enters the scene tree for the first time.
func _ready():

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	if Input.is_action_just_released("Inspect"):
		display_time += 1
		if display_time > 2:
			display_time = 0			
		match display_time:
				$DirectionalLight3D.light_energy = 1				
				$WorldEnvironment.environment.background_color = Color(112,155,255)
				$WorldEnvironment.environment.ambient_light_color = Color(112,155,255)
				$DirectionalLight3D.light_energy = 0.75
				$WorldEnvironment.environment.background_color = Color(232,127,71)
				$WorldEnvironment.environment.ambient_light_color = Color(232,127,71)
				$DirectionalLight3D.light_energy = 0
				$WorldEnvironment.environment.background_color = Color(32,25,80)
				$WorldEnvironment.environment.ambient_light_color = Color(32,25,80)

I want to essentially have different times of day I can display as a snapshot in time. So I set up a simple state check that switches when I do an input.

I am trying to change the background color and ambient light color of my world environment. When I set up the world environment with these variables in godot prior to runtime, it works and looks great, but whenever I switch WorldEnvironment variables in code they either do not seem to work or in this specific case completely bleaches the eyes with the lighting and no longer functions.

I am at a loss for what could be causing this and treid many different approaches, but my initial thoughts make me think that I am jsut not using Node properties in code properly with godot, as prior I also tried using an animationPlayer and just cycling to different frames based on the time of day, but ran into very similar issues where it just never seemed to work, like the animation wouldn’t actually display in game when the inputs were pressed or it would only work if I played the animation and couldn’t just set it to a certain frame.

When you use Color you need to specify the values between 0.0 and 1.0. If you want to use 0 to 255, use can use Color8.

So if you write your line with Color8 like this it should work:
$WorldEnvironment.environment.background_color = Color8(112,155,255)

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.