26 lines
832 B
GDScript3
26 lines
832 B
GDScript3
|
class_name WeatherParticles extends GPUParticles3D
|
||
|
## Particle system that follows the camera.
|
||
|
|
||
|
## How far directly in front of the camera to remain regardless of velocity.
|
||
|
@export var front_flat_distance: float = 1.0
|
||
|
## How many seconds ahead of the camera to remain when it moves.
|
||
|
@export var seconds_ahead: float = 4.0
|
||
|
|
||
|
## Last known position of the camera, for tracking velocity.
|
||
|
var _last_camera_posn := Vector3.ZERO
|
||
|
|
||
|
func _process(delta: float) -> void:
|
||
|
var camera := get_viewport().get_camera_3d()
|
||
|
if camera:
|
||
|
# Track camera velocity.
|
||
|
var camera_velocity := (
|
||
|
camera.global_position - _last_camera_posn
|
||
|
)/delta
|
||
|
_last_camera_posn = camera.global_position
|
||
|
# Reposition particle system.
|
||
|
global_position = (
|
||
|
camera.global_position +
|
||
|
camera.basis.z*front_flat_distance +
|
||
|
camera_velocity*seconds_ahead
|
||
|
)
|