extends Camera2D
@export var start_y: float = -308 # Начало выше
@export var end_y: float = 320
@export var duration: float = 4.0 # 4 секунды - очень плавно
var elapsed: float = 0.0
var is_animating: bool = false
func _ready():
position.y = start_y
elapsed = 0.0
is_animating = true
func _process(delta):
if is_animating:
elapsed += delta
var t = clamp(elapsed / duration, 0.0, 1.0)
# SmoothStep с замедлением
var eased_t = t * t * t * (10.0 - 15.0 * t + 6.0 * t * t)
position.y = start_y + (end_y - start_y) * eased_t
if elapsed >= duration:
position.y = end_y
is_animating = false
set_process(false)
Something like this should work:
extends Camera2D
@export var start_y: float = -308 # Начало выше
@export var end_y: float = 320
@export var duration: float = 4.0 # 4 секунды - очень плавно
func _ready():
var tween: = create_tween()
tween.set_loops()
tween.set_trans(Tween.TRANS_SINE)
tween.tween_property(self, "position:y", start_y, duration)
tween.tween_property(self, "position:y", end_y, duration)
You might need to adjust some values to make it look exactly as you want it to behave.
1 Like
If you want to use a custom interpolator method then you need to use PropertyTweener.set_custom_interpolator() The documentation has an example.
3 Likes