Godot Version
v4.3.stable.official [77dcf97d8]
Question
Hello,
In my game menu, I want to have a sprite that moves a little bit (up and down, using sin).
My sprite is a Sprite2D.
Here’s my code:
extends Sprite2D
var speed = 2 # ( starts to be laggy when it is <5 )
var distance = 10 # the maximum distance the sprite will cover
var time = 0.0 # the time that will increase to get the y by sin()
func _process(delta: float) -> void:
time += delta * speed # increase the time
var y_offset = sin(time) * distance # get the new y of the sprite
self.position.y = y_offset # the the new y
But I don’t know why, when the speed ( speed
) is low ( <5 ) it feels really laggy. Here’s a video: Watch video | Streamable
If someone know why, please tell me.
Thanks!