Bounce / Wave
Make a sprite bounce or wave.
– Sine Amplitude determines the distance moved
– Sine speed determines who fast it moves in those directions
– Do Abs performs an absolute value on the vertex adjustment, so it’s more akin to a bounce
– Do Quantize quantizes the movement to the nearest value, based on quantize_to parameter.
– E.G. Quantize to 1 will only move the sprite in units of 1. Quantize of 0.5, in units of half-pixels, etc.
Shader code
shader_type canvas_item;
group_uniforms Sine;
uniform bool do_abs;
uniform bool do_quantize;
uniform float quantize_to : hint_range(0, 2, 0.1) = 1;
uniform vec2 sine_amplitude = vec2(1.0, 0.0);
uniform vec2 sine_speed = vec2(1.0, 0.0);
void vertex() {
vec2 s = sin(TIME * sine_speed);
if (do_abs) {
s = abs(s);
}
VERTEX += s * sine_amplitude;
if (do_quantize) {
VERTEX = round(VERTEX / quantize_to);
VERTEX *= quantize_to;
}
}
nice
How do you make it move up and down, rather than side to side? Cant figure it out.