Skip to content

This repository contains a custom solution for grass collision in Unity URP. Unlike traditional methods that create a single collision point, this approach uses an orthographic camera to render a top-down view and applies the rendered image as a collision mask on the grass.

License

Notifications You must be signed in to change notification settings

AnderSystems/Unity-Grass-Interaction

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Grass Collision Solution in Unity URP

Description

This repository contains a custom solution for grass collision in Unity URP. Unlike traditional methods that create a single collision point, this approach uses an orthographic camera to render a top-down view and applies the rendered image as a collision mask on the grass. The solution includes a custom shader that lowers the grass based on the alpha channel of the texture.

Features

  • Orthographic Camera: Captures a top-down view of the scene, synchronized with the main camera.
  • Render Mask: Renders only the objects that interact with the grass.
  • Custom Shader: Uses the alpha channel to lower the grass in the collision areas.
  • Pixel Perfect Update: Ensures stable rendering by updating camera coordinates with integer values.

Limitations

  • Distance: The effectiveness depends on the rendering distance of the collision camera.
  • Quality: Higher texture resolution improves collision precision but increases computational load.
  • Object Height: The system only captures a top-down map, which may cause grass to move even if the object is not directly colliding with it.

How to Use

  1. Clone the repository.
  2. Open the project in Unity.
  3. Assign the orthographic camera and configure the render mask.
  4. Apply the custom shader to your grass material.
  5. Adjust the settings as needed to fit your scene.

Contributing

Feel free to fork this repository and submit pull requests. Any contributions to improve the solution are welcome!

License

This project is licensed under the MIT License.

About

This repository contains a custom solution for grass collision in Unity URP. Unlike traditional methods that create a single collision point, this approach uses an orthographic camera to render a top-down view and applies the rendered image as a collision mask on the grass.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages