Move OmniLight randomly around starting Point

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By akirahinoshiro

Hi,
I try to do some flickering camp fire.
The light itself is somewhat changing the energy.
To make it more realistic I want some moving shadows on top.
So what I want is some slightly moving light source around the parent position.
What I have is a constantly (somewhat random) translating and moving away light source.

extends Spatial
func _ready():
    pass
func _process(_delta):
    $light.light_energy = .5 + randf()*.5+.5
    $light.translate(Vector3(randf()*.01,0+randf()*.01,0+randf()*.01))

Thanks for any advice

PS: using Godot 3.2.1

:bust_in_silhouette: Reply From: Magso

Store the random Vector3 as a variable and lerp to it.

var target : Vector3

func _ready():
    while true:
        target = Vector3(randf()*11+1, randf()*11+1, randf()*11+1)
        yield(get_tree().create_timer(0.5),"timeout")

func _process(delta):
    $light.translation = lerp($light.translation, target, delta*2)

Ah thanks that helped I needed to change the target value not only in _ready() and then it worked.

akirahinoshiro | 2020-04-04 15:23