Sin oscilation in rotation

Godot Version

4.3

Question

i was just trying to make a simple script to make swaying lights easier for me, im just using the sine of time. im kinda stuck at actually rotating the light though, i dont really know what all the different rotation functions and values do either. my first thought was just “rotation.x = rotaton.x * sine” but that didn’t work. any help apreciated!

extends SpotLight3D

@export var rotation_axis: String
@export var amplitude := 1.0
@export var frequency := 1.0
var time: float

func _process(delta: float) -> void:
	time += delta
	
	var sine = sin(time * frequency) * amplitude
	if rotation_axis == "x":
		pass
	elif rotation_axis == "y":
		pass
	elif rotation_axis == "z":
		pass

About rotation.x = rotation.x * sine:
As soon as sin(time) results in 0, your rotation.x will be set to 0 and can’t ever increase afterwards.

So instead, you should just use rotation.x = sine. (In case you have some default offset for rotation.x, you can just add that to sine.)

2 Likes