Is it bad practice to use wave forms for animation? (sin waves and the like)

Godot Version

4.2.1

Question

I am a very beginner programmer.

I really hate making animations in blender, especially really basic ones (floating, shaking etc) so as I’ve started getting used to coding in gdscript i’ve gotten excited at the idea of using math to do simple animations instead of using blender. For example I thought I could use a sin wave in the global_position.y of an object to get it to move smoothly up and down instead of needing to make a seperate animation for it in blender.

But then when I tried to use a sin wave in this way the code started randomly breaking. It would work with some values, but would not work with other values. Some values would randomly make a child node null while others wouldnt (I still can’t figure out why this is happening, those specific values on their own won’t crash the program, but for some reason when the sin wave produces that value it does break)

This is making me think that maybe using sin waves and other maths to move things might not be a good idea and maybe I should just use animations like normal.

So my question, Is it bad practice to use maths and waves to make rudimentary animations, or is it normally safe to do?

Is it bad practice to use maths and waves to make rudimentary animation

It is not a bad practice, use waves, use noise generators, they are super practical and are useful for those things

the code started randomly breaking

This seems strange

Some values would randomly make a child

This seems stranger

Share the code to see what happens there

1 Like

Thanks for the help! Unfortunately the code is just from a “learning” project, so it’s a giant giant mess right now. If i sent it to you it would probably be a lot of work to sort through haha. But yeah if theres no problems with using waves and stuff I will keep using them in future projects. Thanks again!

i use this for levitate/rotate coins
image

extends Node3D

var time:float=0
@onready var inner:Node3D=get_node("./coinModel")

func _ready():
	pass

var frequency:float=3
var amplitude:float=40
var rotationSpeed:float=2
func _process(delta):
	time+=delta
	var offset=cos(time*frequency)*amplitude
	inner.position.y=offset*delta
	rotate(Vector3(0, 1, 0), rotationSpeed*delta)
1 Like