Godot Version
4.4
Question
I’m trying to setup my tree sprite to briefly shake on-hit with an axe. I want the tree to shake more on the top than the bottom. I’m using a shader to do this, and my shader code looks like:
shader_type canvas_item;
uniform float shake_intensity = 0.0;
uniform float shake_speed = 20.0;
void vertex() {
if (VERTEX.y < 0.0) {
VERTEX.x += sin(TIME * shake_speed + VERTEX.y) * shake_intensity;
}
}
This looks GREAT in the editor, but when I test my scene with the tree sprite in it, only 2/3 of my tree shakes. It’s like there’s an invisible line just above my bottom set of leaves, and I’m pivoting around that axis. Why would I only see this when testing and not in the editor – what am I missing?
Hi,
I could be wrong here, but I believe you want to use the vertex world position (at least it’s worth a try).
As in the docs:
shader_type canvas_item;
render_mode skip_vertex_transform;
void vertex() {
VERTEX = (MODEL_MATRIX * vec4(VERTEX, 0.0, 1.0)).xy;
}
Let me know if that works. If not, could you attach some images to show the issue?
Thanks for the docs link – was a good read!
I tried a few different variations in my shader code using the newly defined VERTEX you have above but always landed with the same problem. It manifests like this:
In the Editor:
In my running scene:
I figured it out! In my Project Settings > Stretch > Mode:
Changing to canvas_items fixed things right up.
Ahh thank you so much. I am doing the same tutorial and my trees were bugging out so badly. This made the shader apply so much more consistently. No weird half shakes depending on where I hit the tree, pixel glitches, etc. 