Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

How do I create bouncy ball object like rubber?

Discussion in 'Scripting' started by shinriyo_twitter, Aug 12, 2011.

  1. shinriyo_twitter

    shinriyo_twitter

    Joined:
    Aug 12, 2011
    Posts:
    328
    I'd like to create bouncy ball object which make change.
    I think that I must use mesh renderer.
    But, I don't know how to this.


    I guess I may use like that.
    Code (csharp):
    1.  
    2.     var mesh : Mesh = GetComponent(MeshFilter).mesh;
    3.     var vertices : Vector3[] = mesh.vertices;
    4.     var normals : Vector3[] = mesh.normals;
    5.  
    6.     hoge bar;
    7.  
     
  2. Headingwest

    Headingwest

    Joined:
    May 3, 2011
    Posts:
    153
    Attach a rigid body to a sphere and apply the "Bouncy" physics material from the standard assets?
     
    Last edited: Aug 12, 2011
  3. zine92

    zine92

    Joined:
    Nov 13, 2010
    Posts:
    1,347
    Couldn't have said it better. And take a look at this.

    Edit: If it's mesh deformation you are talking about, not sure how to do it but you can check out Mega-fiers
     
    Last edited: Aug 12, 2011
  4. Headingwest

    Headingwest

    Joined:
    May 3, 2011
    Posts:
    153
    Re-reading it im beginning to suspect he wants a soft body effect so the ball deforms when it hits the ground....
     
  5. shinriyo_twitter

    shinriyo_twitter

    Joined:
    Aug 12, 2011
    Posts:
    328
    Thank you for replying

    Re:Headingwest
    >Attach a rigid body to a sphere and apply the "Bouncy" physics material from the standard assets?
    thanks. but, It is not I wanted to say. I wanna make to "change shape" the ball.

    >a soft body
    Yes, I want to say. I couldn't explain in English well...

    Re:zine92
    >Mega-fiers
    It is my image. but, It is not free.
    Can you show me a JavaScript code?
     
  6. shinriyo_twitter

    shinriyo_twitter

    Joined:
    Aug 12, 2011
    Posts:
    328
    And, I want to use it in both iOS and Android.
     
  7. zine92

    zine92

    Joined:
    Nov 13, 2010
    Posts:
    1,347
    Actually scripts you write can be compiled to both provided you have the licenses for both. But as to how to do mesh deformation. I am not too sure about it. Can't help you much.
     
  8. VCCGeek

    VCCGeek

    Joined:
    Nov 17, 2009
    Posts:
    89
    If all you want is a stretch/squash, then you could just scale the mesh along a specific axis.

    Code (csharp):
    1.  
    2. void OnCollisionEnter(Collider other)  {
    3.    
    4.    float XScale = transform.localScale.X;
    5.    float YScale = transform.localScale.Y;
    6.    float ZScale = transform.localScale.Z;
    7.  
    8.    YScale = Mathf.MoveTowards(YScale, 0.6f, 0.03f);
    9.  
    10.    transform.localScale = new Vector3(XScale, YScale, ZScale);
    11.  
    12. }
    13.  
    You'd need to do a lot of modifications to that script to make it work, especially if you're doing your project in JS, but it shows the general idea.

    Hope that helps!
     
    Last edited: Aug 12, 2011
  9. g0tNoodles

    g0tNoodles

    Joined:
    Nov 28, 2010
    Posts:
    193
  10. shinriyo_twitter

    shinriyo_twitter

    Joined:
    Aug 12, 2011
    Posts:
    328
    HI
    do you mean "Crumple mesh modifier"?
     
  11. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,688
    Added a rubber material modifier to MegaFiers might be what you are looking for.
     
    Last edited: Nov 2, 2017
  12. TiG

    TiG

    Joined:
    Feb 28, 2011
    Posts:
    311
  13. Mornedil

    Mornedil

    Joined:
    Feb 7, 2016
    Posts:
    19
    Apologies for bumping such an old thread, but this thread still comes up when googling this question but there's no real answer or solution here.
    I looked around for a while and found this FREE asset on the unity web store that lets you create softbody physics: https://www.assetstore.unity3d.com/en/#!/content/62991 (it's called Bullet Physics For Unity)
     
    Cookieg82 likes this.
  14. Fimiam

    Fimiam

    Joined:
    Oct 24, 2016
    Posts:
    11
    That's really amazing man, thanks a lot !!
     
  15. ExNinja

    ExNinja

    Joined:
    Dec 4, 2013
    Posts:
    29

    Attached Files: