How to make a interactive grass in 3d game?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By icqqq

As in game Breath of the Wild or Horizon Zero Dawn,
you can see the grass will have reaction when player pass through them

How can I make the similiar effect in Godot?


:bust_in_silhouette: Reply From: Oen44

You have to apply collision to grass and change it’s rotation (based on direction) when player collides (step, roll etc.). That’s something you could expect from AAA games, I don’t think that Godot is capable of processing that amount of calculation without massive performance drop. You could optimize it by enabling collision at run-time when player is near grass, so CPU won’t have to calculate grass that is on the other side of map.

:bust_in_silhouette: Reply From: Xrayez

First, take a look at this shader asset:

Godot Simple Wind Shader 2D - Video Demo
Godot Simple Wind Shader 2D - Source

Just to give an idea, I think you can achieve what you want by modifying/creating some of the shader’s uniform variables to rotate/bend/scale the grass from player’s script, though I don’t know how to implement it.

:bust_in_silhouette: Reply From: SIsilicon

Take a look at this. The last part of the page shows a way to simulate object-grass interaction. It basically shows that you can simulate great displacement with shaders. Just like how you would with wind(as the other answer has shown).
Pass the position of the interacting object into shader (in world space), calculate the vector from that position to the grass vertex (also in world space), and finally displace the vertex along that vector.

How can I pass the position of the interacting object to the grass shader?
Should I pass it for all grass in each frame?
Or in other way?

Thank you!

icqqq | 2018-09-22 04:13

Just pass the global position of the interacting object to your grass’s shader every frame. Or else when the body moves, it won’t be consistent with the grass.

SIsilicon | 2018-09-22 04:30

:bust_in_silhouette: Reply From: Vis

this video is helpful