Interactivity

This page covers the setup and usage of interactive grass features. Make sure you have first gone through the setup of the grass shader and can follow along using your mesh setup in the scene.

Video Tutorial

Quick Setup

To add interactive behaviour to the grass, you need to input the Grass Manager into the scene, as well as Grass Interactor onto any object you want interactive behaviour from.

Additionally, if you are looking for interactive behaviour for the mouse, you will need to add the Grass Mouse Interactor script onto the main camera in your scene. All of it covered below.

Grass Manager

The Grass Manager is responsible for managing all interactive grass elements in the scene. There is also global settings for the wind and recovery of the grass from interactions.

Area Settings

A+ Grass Area Settings

Area Settings let you define the interactive areas for the grass. By default the value is low, so if you need a larger area or if your camera is zoomed out a lot, you need to look into adjusting these settings.

Active Area Size determines the size of the world space area where grass will be interactive.

Recenter Threshold How far the center of the interactive area can move before it recenters. Lower value means it recenters more frequently.


Wind Settings

A+ Grass Wind

Wind Settings let you adjust the wind dynamically at runtime for a real weather effect.

These settings are covered in the Getting Started section.

Grass Recovery

A+ Grass Recovery

Grass Recovery settings allow you to control how the grass returns to its original state after being interacted with. These are global values and will affect all of the grass in the scene.

Recovery Speed adjusts how quickly the grass returns to its original state after being interacted with. Recovery Delay adjusts the delay before the grass starts to recover after being interacted with.

Recommended Settings: For natural behavior, use low values for both Recovery Speed and Recovery Delay.

Runtime Changes

Important! There is a method called ResetGrass( ) which Resets Grass Data.

If you want to change grass at runtime, you can call ResetGrass which is inside of the Grass Manager script. You can see an example of this inside of Demo01 scene, with this method being called inside the Canvas on the buttons that switch the grass fields. Without it, when you switch between the fields whilst interacted and bent grass, that bend data will stay and transfer to the new field.

Grass Interactor

The Grass Interactor is responsible for handling the interactions between the grass and other objects in the scene. It allows objects to affect the grass, bending and pushing it. You can have as many interactors in the scene, just make sure to add the Grass Interactor component to each.

Interaction Settings

A+ Grass Interaction Settings

These values are per interactor so each interactor can behave differently.

Recover On Idle gives you an option to enable or disable recovery when the interactor is idle, so the grass can return to its original state even if the interactor is in that position.

Push Rate acts as strength that gets applied to the grass when on top of the grass. This value accumulates and can intensify the push effect with continuous movement in the same area.

Maximum Rate limits how much of the push rate can be accumulated.

Motion Detection

A+ Grass Motion Detection

You can limit at what speed interaction takes place with Movement Threshold But generally keep this value below 1, at low threshold to prevent any jitter as with value of 0 it will always keep updating the grass and pushing it based off interactor's position. Use gizmos to view this (It turns yellow when in motion)

Detection Radius determines the area around the interactor where it can detect and affect the grass. Adjusted depending on the size of your character/interactor.

If you need to change the position of where the interaction takes place use the Position Offset to adjust the center of the detection radius.

A+ Grass Gizmos

At the bottom you have the option to turn on/off the gizmos for the grass interactor to see the size of the detection radius, and where it is depending on the position offset.

A+ Grass Gizmos Preview

Mouse Interaction Handler

The Mouse Grass Interaction Handler provides data from the mouse position off the camera using a ray to allow an interactor to follow the mouse position and interact with the grass.

Setup

A+ Grass Mouse Handler Setup

Assign an empty game object with the Interactor component to the Mouse Grass Interaction Handler. This gameObject will follow the mouse position and interact with the grass where the ray hits.

Include inside the Interactive Layer all of the layers you want the mouse handler to interact with.

Distance value determines how far the ray from the camera will reach.

A+ Grass Mouse Handler Gizmos

At the bottom you have the option to turn on/off the gizmos for the mouse handler to preview the distance of the ray from the camera.

A+ Grass Mouse Handler Gizmos Preview

If you like the asset, please consider leaving a review!

Leave A Review