Godot Version
4.5
Question
How do I animate the selected vertices of this really simple model, in Godot 4.5?
I’ve got a landscape filled with a bunch of really simple 2D planes for plants, and I want to animate them as if wind is blowing through them. I have a few ideas of how I might simulate that via vertex animation, but I’m so far just trying to figure out how to set that up. I at first thought I could just assign everything to a simple vertex group, but it looks like .glb’s don’t retain vertex group information. So that’s not an option like I hoped it was.
I also considered possibly doing something like just adding simple bones to every instance of the flowers, but I’m worried about that getting too resource intensive. For reference, here’s a screenshot of the model I’m looking at:
(its just ripped assets from a DS game that I rearranged and repainted, the textures themselves are not mine).
Is there no way to tell blender to select an individual vertex or pair of vertices on a mesh and animate those, beyond adding animation bones to everything? I’m currently watching youtube videos in another window looking for insights on how to solve this problem but if anybody has a general idea of a solution or a better place to find one, please let me know. Or, if somebody wants to correct me that “a bunch of simple animation bones wouldn’t be too intensive for a scene like this” or something.
Thanks in advance!
You may want to watch vertex shader animation videos. It looks to me you want something that makes your textures wave like flags or grass, so the way normally done is with shaders.
https://share.google/aimode/J0hLyo8vSmbrUR178
Ah, I think I see what’s going on here- instead of changing the shape of the mesh, they’re changing the image that’s on the mesh.
I don’t know if that’s necessarily appropriate for what I want, though; my hope here is that the player could rotate the camera 260 degrees around the middle of the scene and still see the plants waving in the breeze, which would need the meshes to twist and move in a 3D space. Just the flat images alone wouldn’t cut it.
The more I stare at this problem, the more I’m starting to think a skeleton 3D and armatures attached to the mesh is the way to go. I think.
Shaders can also modify the vertex positions. For example, you can add some offset to VERTEX.xz depending on TIME (and multiplied by (1.0 - UV.y), so that only the upper vertices move).
Right, right, you’re the second person to recommend that to me- I’m currently working through this problem moreso in real time on the godot discord server. It’s an interesting thought, and it could certainly work. The only problem I immediately notice is not every flower is perfectly flatly vertical. Often times I manipulate each individual flower scene to be more in flush with the landscape, so it looks more organic. They end up looking something like this:
It could still work, though.
One of my concerns is, I know in either case I’d be making multiple instances of the same flowers, but I still want to be able to manipulate each flower individually after being instanced, before the game starts, so they all blow in the same wind but they all blow juuuuust a bit differently, are juuuuuust a bit different in size and shape, etc. It’s possible to edit individual instances of a scene, right? I sure hope so lol.
Just throwing this out there, since someone else mentioned it: Someone told me "Hey by the way bones are really resource expensive in Godot, so if you’re doing a whole lot of plants like this, you’ll want to use shaders. So I’m definitely switching to shaders. Thank you to everyone who was nudging me in that direction.
I’m currently staring at this model getting ready to try to read and write some script that will help make the flowers look like they’re blowing in the wind. I’ll post updates here once I think I have a grasp of what I’m reading.
There is also a Godot website dedicated to shaders developed by individuals.
Just search for grass
Very handy website! This looks an awful lot like what I’m going for. Someone else suggested to me I start going through this website too, and looking at the script to deliberately try to break/alter things to get a feel for how shaders are written. I may very well do that, here.
So this is what I’ve got so far for the evening:
I’ve been taking Clearcode’s Udemy course for Godot, and I’ve got a big googledoc that’s more than 200 pages long now from which I’ve been taking detailed notes on everything- thankfully I was able to refer to it to remember how to get as far as this in Godot (though not without first asking for help from more experienced devs).
The screenshot above is totally untouched script, naturally left over after converting from StandardMaterial3D to ShaderMaterial3D. So my next goal is to figure out how to take this code from the grass shader above:
and just copy/paste it into my code, without breaking anything. We’ll see if I can manage that.
Edit: Now I think, THINK, after reading my block of code and their code here, the only real notable change is the “VERTEX.x” and the “VERTEX.z” additions in lines 8 and 9. It looks like every other change is just something left over from our materials to begin with. This is all the code for how the X and Z vertices are moving, and its as simple as that. I’m going to try to copy/paste it and see if it works. If it does, I’m going to really stare at this and see if I can make it work/edit it to my liking.
Alright, I’m just coming back here to mark this as “solved.” If anyone else reading this thread is a beginner like me who wants to learn to do this, the solution really is this simple:
- import your .glb model, complete with your material.
- Go through the whole process to convert your material into a shader material; I can’t detail that here right now.
- Open up the script for the shader with the somehow-not-GLSL-code, this thing:
- See that bit at the bottom? void vertex()? Make a new line right under the UV part, and copy paste this bit of code in there:
VERTEX.x += sin(NODE_POSITION_WORLD.x + TIME * 1.25 + UV.y) * ( 1.0 - UV.y) * 0.2;
VERTEX.z += cos(NODE_POSITION_WORLD.z + TIME * 0.45 + UV.y) * ( 1.0 - UV.y) * 0.15;
And presto! Your plant is now swaying.
To fine tune the results you can just edit the formula for the X and Z axis of the vertices. I’m going to be spending some time seeing if I can figure out how to do exactly that; my next goal is to try to make a way to make the wind blow hard in one direction, then slow down, then increase speed again.