How to make a softbody bouncier in Unity 2D?

727 views Asked by At

I made a jelly softbody in Unity, and I've tried to make it bouncier (so that after an object lands on it, it bounces into the air higher than it does normally), but I can't seem to figure out how to do it. I've tried to alter every single aspect of the objects to bounce and the jelly itself that I could find, such as spring joint frequency, and rigidbody components for the softbody, but nothing made it bounce more from the jelly. I followed this tutorial: https://www.youtube.com/watch?v=3avaX00MhYc but made a center bone instead of using bones on opposite sides. Here are some screenshots of different aspects: https://i.stack.imgur.com/KWhUs.jpg This has been stumping me for the past week now, so I would appreciate any ideas.

1

There are 1 answers

0
Omega Productions On

I've figured it out and it turns out I just needed to add force to the object to bounce OnCollisionExit with the softbody as well as add force to the softbody bones downwards OnCollisionEnter with an object so it still maintains the effect. Here's my code if anyone else would like to implement something like this into their game:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class jellyBounce : MonoBehaviour
{
    public int speedBounce = 500;
    public int speedInward = 500;

     void OnCollisionEnter2D(Collision2D other)
     {
         if (other.gameObject.tag == "BounceMe")
         {
             speedInward = 300;
             gameObject.GetComponent<Rigidbody2D>  ().AddForce(Vector2.down*speedInward);
         }
         else if (other.gameObject.tag == "AlreadyBouncy")
         {
             speedInward = 50;
             gameObject.GetComponent<Rigidbody2D>().AddForce(Vector2.down*speedInward);
         }

     }

     void OnCollisionExit2D(Collision2D other)
     {
         if (other.gameObject.tag == "BounceMe")
         {
             speedBounce = 600;
             other.gameObject.GetComponent<Rigidbody2D>().AddForce(Vector2.up*speedBounce);
         }
         else if (other.gameObject.tag == "AlreadyBouncy")
         {
             speedBounce = 100;
             other.gameObject.GetComponent<Rigidbody2D>().AddForce(Vector2.up*speedBounce);
         }

     }
}