Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by pachash · Aug 09, 2014 at 08:08 PM · spritegrasswind

Sprite grass/trees and wind simulation

Folks, would you please recommend the best way to simulate slight bending of grass and trees?

My grass and trees are 2d sprites, rendered with the sprite renderer and the game uses orthographic camera. I replaced default sprite shader with my own one which skewed vertices by some angle. Well, it kinda works but I'm not satisfied with results.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image JDuaneJ · Oct 25, 2014 at 12:32 AM 0
Share

I've been searching for a solution for this as well. Any updates?

avatar image pachash · Mar 05, 2015 at 10:00 AM 0
Share

Yep! What I'm currently using is animation of vertices. However for this I had to migrate all my sprites to mesh renderers. Looks like sprite won't allow you to play with its mesh.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by pachash · Mar 05, 2015 at 11:15 AM

Looks like I managed to find an answer to this problem myself. The way to go is to play around with mesh vertices or UVs. However looks like it is only possible for regular meshes not sprites. So I had to make all my sprites regular meshes with mesh renderers attached.

After this I attach some script to every instance I'd like to be animated, e.g:

 using UnityEngine;
 using System.Collections.Generic;
 
 public class AnimateTree : MonoBehaviour
 {
   Mesh mesh;
   Vector3[] verts_ref;
   Vector3[] verts;
   float time_offset;
 
   void Start()
   {
     mesh = GetComponent<MeshFilter>().mesh;
     verts_ref = mesh.vertices;
     verts = new Vector3[verts_ref.Length];
     System.Array.Copy(verts_ref, verts, verts_ref.Length);
     time_offset = Random.Range(0, 10000);
   }
 
   void OnBecameInvisible()
   {
     enabled = false;
   }
 
   void OnBecameVisible()
   {
     enabled = true;
   }
 
   void Update()
   {
     float time = time_offset + Time.time;
     float x_tweak = 0.060f;
     float y_tweak = 0.0085f;
     float val_x = Mathf.Sin(time);
     float val_y = Mathf.Cos(time);
     float k = 1.0f;
 
     for(int i=(int)(verts.Length*0.4f);i<verts.Length;++i)
     {
       Vector3 v = verts_ref[i];
 
       if(i%5 == 0) k = 1.0f;
       if(i%5 == 1) k = 1.2f;
       
       v.x = v.x + k * x_tweak*val_x;
       v.y = v.y + k * y_tweak*val_y;
       verts[i] = v;
     }
     mesh.vertices = verts;
   }

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by rubendariohh · Dec 31, 2017 at 04:41 PM

Hi Pachash, how you convert your sprites into meshes? thanks!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple terrains and how LoD works 0 Answers

[SOLVED] Which is faster and more efficient? 2 Answers

Wind: Detail meshes are moved by wind back and forth, rather than swaying: how do I make them sway? 7 Answers

Shimmering waves of wind-blown grass possible? 1 Answer

making grass move at different speeds 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges