add 'follow camera'
This commit is contained in:
@@ -12,6 +12,7 @@ var fog_overlay: ColorRect
|
||||
var sun: DirectionalLight3D
|
||||
var environment: WorldEnvironment
|
||||
var environment_config: EnvironmentConfig
|
||||
var camera: Camera3D
|
||||
|
||||
var day_time: float = 0.0
|
||||
|
||||
@@ -36,7 +37,8 @@ var thereare_fireflies: bool = false
|
||||
|
||||
func _init(wind: GPUParticles3D, snow: GPUParticles3D,
|
||||
fireflies: GPUParticles3D, rain: GPUParticles3D, ray: PackedScene,
|
||||
thesun: DirectionalLight3D, theenvironment: WorldEnvironment, environmentconfig: EnvironmentConfig) -> void:
|
||||
thesun: DirectionalLight3D, theenvironment: WorldEnvironment, environmentconfig: EnvironmentConfig,
|
||||
thecamera: Camera3D = null) -> void:
|
||||
particles_wind = wind
|
||||
particles_snow = snow
|
||||
particles_fireflies = fireflies
|
||||
@@ -45,6 +47,7 @@ func _init(wind: GPUParticles3D, snow: GPUParticles3D,
|
||||
sun = thesun
|
||||
environment = theenvironment
|
||||
environment_config = environmentconfig
|
||||
camera = thecamera
|
||||
|
||||
set_rain()
|
||||
|
||||
@@ -64,7 +67,9 @@ func _ready() -> void:
|
||||
UIEvents.toggle_fireflies.connect(toggle_fireflies)
|
||||
UIEvents.toggle_storm.connect(toggle_storm)
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
func _process(delta: float) -> void:
|
||||
_follow_camera()
|
||||
|
||||
var base_tint: Color
|
||||
var base_sky_top: Color
|
||||
var base_sky_horizon: Color
|
||||
@@ -187,6 +192,19 @@ func _process(delta: float) -> void:
|
||||
environment_config.material_fog.set_shader_parameter("sun_color", final_tint)
|
||||
|
||||
|
||||
func _follow_camera() -> void:
|
||||
if not camera or not is_instance_valid(camera):
|
||||
return
|
||||
var cam_pos: Vector3 = camera.global_position
|
||||
if particles_rain:
|
||||
particles_rain.global_position = Vector3(cam_pos.x, particles_rain.position.y, cam_pos.z)
|
||||
if particles_snow:
|
||||
particles_snow.global_position = Vector3(cam_pos.x, particles_snow.position.y, cam_pos.z)
|
||||
if particles_wind:
|
||||
particles_wind.global_position = Vector3(cam_pos.x, particles_wind.position.y, cam_pos.z)
|
||||
if particles_fireflies:
|
||||
particles_fireflies.global_position = Vector3(cam_pos.x, particles_fireflies.position.y, cam_pos.z)
|
||||
|
||||
#region fireflies
|
||||
|
||||
func toggle_fireflies(value: bool):
|
||||
@@ -210,7 +228,6 @@ func set_fireflies():
|
||||
|
||||
func toggle_wind(value: bool):
|
||||
is_windy = value
|
||||
var is_storm = is_raining and is_snowing
|
||||
var is_night = day_time >= 2.5
|
||||
|
||||
if particles_wind:
|
||||
@@ -359,8 +376,10 @@ func spawn_single_godray() -> void:
|
||||
var random_x: float = randf_range(-environment_config.godray_spawn_radius, environment_config.godray_spawn_radius)
|
||||
var random_z: float = randf_range(-environment_config.godray_spawn_radius, environment_config.godray_spawn_radius)
|
||||
|
||||
#TODO: FLAVIO: fix global position using the camera position if needed
|
||||
ray.global_position = Vector3(random_x, environment_config.godray_spawn_height, random_z)
|
||||
var center := Vector3.ZERO
|
||||
if camera and is_instance_valid(camera):
|
||||
center = camera.global_position
|
||||
ray.global_position = Vector3(center.x + random_x, environment_config.godray_spawn_height, center.z + random_z)
|
||||
ray.rotation_degrees = environment_config.godray_rotation_degrees
|
||||
ray.scale = environment_config.godray_scale
|
||||
|
||||
|
||||
Reference in New Issue
Block a user