- Home /
shrinking according to mass
so this script shrinks an at a constant rate depending on mass. so when an object enters the trigger collider, if it has more mass than this object, then this object will beguin shrinking at a rate depending on how much mass it has. but i want the rate of shrinking dependent on the difference in mass between the two objects. so if i have one object with a mass of 100 and the other with a mass of 99. the one with a mass of 99 will shrink slowly at first and speed up the smaller it gets. then say an object has a mass of 1000 and the other has a mass of 99, the object with the mass of 99 will shrink very fast . how can i do this? here is the script.
 private Rigidbody rb;
 private float originalMass;
 private Vector3 originalScale;
 private float counter;
 public float timeToShrink;
 private Vector3 someVector;
 private bool hasEntered;
 float shrinkFactor;
 
  void Start()
 {
     rb = GetComponent<Rigidbody>();
     originalMass = rb.mass;
     originalScale = transform.localScale;
   
   
 }
 void ShrinkBabyShrink(float shrinkFactor, Vector3 targetScale, float targetMass)
 {
     Vector3 newScale = Vector3.Lerp(originalScale, targetScale, shrinkFactor);
     float newMass = Mathf.Lerp(originalMass, targetMass, shrinkFactor);
     transform.localScale = newScale;
     rb.mass = newMass;
 }
 void Update()
 {
     
     if (hasEntered && shrinkFactor <= 1)
     {
         counter += Time.deltaTime;
         float shrinkFactor = counter / (timeToShrink * originalMass);
         ShrinkBabyShrink(shrinkFactor, someVector, 3);
     }
 }
 void OnTriggerEnter(Collider other)
 {
     if (rb.mass < other.GetComponent<Rigidbody>().mass) 
     {
         hasEntered = true;
     }
 }
 private void OnTriggerExit(Collider other)
 {
     hasEntered = false;
 }
}
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                