Wobble animation
Wobble animation with adjustable amplitude, reset cooldown, and pivot point (the pivot point doesn’t work well, so it’s best to use a sprite offset from the center)
Shader code
shader_type canvas_item;
uniform float rotation_speed = 2.0; // Скорость вращения (радиан в секунду)
uniform float reset_time = 2.0; // Время полного цикла анимации
uniform vec2 rotation_offset = vec2(0.5, 0.5);
// Функция для вычисления текущего угла вращения с плавной анимацией
float get_rotation() {
// Получаем текущее время
float time = TIME;
// Вычисляем фазу анимации (от 0 до 1)
float phase = mod(time, reset_time) / reset_time;
// Создаём плавную синусоидальную анимацию
// sin(phase * 2 * PI) даёт плавное движение от 0 -> +1 -> 0 -> -1 -> 0
float smooth_phase = sin(phase * 2.0 * 3.14159);
// Применяем скорость вращения
float rotation = smooth_phase * rotation_speed * reset_time * 0.5;
return rotation;
}
void fragment() {
// Получаем текущий угол вращения
float current_rotation = get_rotation();
// Делаем вращение зависимым от UV (для "якоря" внизу спрайта)
float rotation_anchored = current_rotation * (1.0 - UV.y);
// Создаём матрицу вращения
mat2 rotation_mat = mat2(vec2(cos(rotation_anchored), sin(rotation_anchored)),
vec2(-sin(rotation_anchored), cos(rotation_anchored)));
// Смещаем UV для применения вращения
vec2 centered_uv = UV - rotation_offset;
// Применяем вращение
vec2 rotated_uv = centered_uv * rotation_mat;
// Возвращаем UV обратно
rotated_uv = rotated_uv + rotation_offset;
COLOR = texture(TEXTURE, rotated_uv);
}

