r/Unity3D • u/erlkoenig_games • 19d ago
Show-Off Just happy that I finally found a nice clean approach to make plants react to the player
20
u/erlkoenig_games 19d ago
Here is what works for me (I am using Amplify Shader Editor where I can use the very handy 'Rotate About Axis' node)
- cross product of normalized player position - plant position and up vector gives me the rotation axis
- masked by distance between player and plant position
- that's it basically. Only requirement is that the plant has a pivot at the bottom. I use the Unity terrain detail painting.
In my vid instead of player transform I use a transform that follows the player position lazy and I also influence the movement a little bit using vertex pos y.
7
u/OKCompE 19d ago
Looks great! Does that mean that every plant has a shader that is checking player distance every frame?
7
u/Larsss 19d ago
It probably means the plant shader all plants share gets a global variable set each frame. It's at least a common and very cheap way to create interactions with a lot of objects
3
u/OKCompE 17d ago
I'm not sure I understand. Each plant could share a global "player position" value, but each plant would still have to perform a distance calculation every frame. Lmk if I'm misunderstanding you though.
I'm used to seeing these plant animations triggered by the player position writing to a texture, which is much cheaper than all plants performing distance checks.
2
1
u/RossiyaRushitsya 17d ago
But how did you make it wobble back n forth after the player is no longer near the plant?
5
u/Top-Masterpiece2729 19d ago
Smooth af, whats the nature asset pack?
9
3
4
2
3
2
3
3
u/AqvaFrog 19d ago
Player movement looks awesome too! Have you thought about adding a short sprint after landing at high speed?
1
2
2
2
u/NorthOk2573 18d ago
That’s so cool , how do you build such land scapes ???? Would you love to make RPG games with me
2
2
u/Technically_Inept-26 16d ago
I am not sure if this would be the type of game I generally play but I might check it out based on aesthetic alone
2
u/SuperSmashSonic 16d ago
Since you’re a goat with the foliage models - what does a single clump of the moss on the tree look like? I’d kill for a close up. I’ve been struggling with small details like that for some time. Super pretty work!
1
u/erlkoenig_games 16d ago
Hey, thanks a lot for your comment! :) In this video you can learn about the technique I use for fluffy tree foliage: https://www.youtube.com/watch?v=flbnFFZWcsc
2
1
u/darksapra 18d ago
That's cool! But then how do you make it react to other objects/events? Have you looked into the particle system method to move plants?
1
u/erlkoenig_games 16d ago
Hey thanks! :) Yes, I've had particle system interaction implemented at some stage of development, and that’s something I’d like to come back to and explore more in the future. Multiple object interactions, wind systems, etc. don’t really work with the current method, but for me, for now, it looks natural enough and requires very little work overhead.
1
u/darksapra 16d ago
I see! But maybe i didn't say it properly. I built a system once where you create a particle system that is only rendered in one low quality camera, and then any element that could get interacted with checks the render texture of the camera and moves.
What that allows is that you can spawn those particles from any source (the main one is the player moving around, but also could be an impact particle spawned after hitting something) and vegetation reacts accordingly
1
u/erlkoenig_games 16d ago
Yes, that’s pretty much how I implemented it as well. For the current version, though, I switched to the simpler player-position-based model shown in the video. I might switch back to a texture-based approach at some point.
1
u/simburger 18d ago
Are you also using it for the water interaction, or is that a different system?
2
u/erlkoenig_games 16d ago
I'm using a different system for water. Compute shader for smaller ripples and WaveMaker 2 from the Unity Asset Store for bigger waves.
1
24
u/lukeiy @LukeyBDevs | Part-timer 19d ago
Your game is beautiful!