- Home /
shrinking mass and scale
with this script how can i make it so that the objects scale shrinks at the same rate as the mass shrinks, so the scale will reach 0 at the same time the mass does?
 float scale;
 private Rigidbody rb;
 private Rigidbody otherRB;
 Vector3 temp;
 // Use this for initialization
 void Start()
 {
     rb = GetComponent<Rigidbody>();
     scale = .01f;//(rb.mass - otherRB.mass) / 300;
 }
   
 void OnTriggerStay(Collider other)
 {
     
   
     otherRB = other.GetComponent<Rigidbody>();
     if (other.gameObject.tag == "Death")
     {
         
         temp = transform.localScale;
         temp.x -= scale;
         temp.y -= scale;
         temp.z -= scale;
         rb.mass -= (rb.mass - otherRB.mass)/300;
         transform.localScale = temp;
     }
         
 }
Answer by Vallar · Jul 15, 2018 at 02:49 AM
Right now you are reducing each of the scale axis by 0.1f (if I am not mistaken). To reduce the mass by the same "percentage" you'll need to calculate the percentage of the scale's axis reduction value. So you'd probably do something like float percentage = .1f / temp.x; This is basically the percentage of the amount you need to scale the mass with.
For mass you'll do something like deductionValue = mass * percentage / 100; and you'll get the exact amount you want to deduct from mass so later you can do mass -= deductionValue.
Hope that helps/works.
Your answer
 
 
             Follow this Question
Related Questions
shrinking according to mass 0 Answers
Warning: "Setting scale failed, ignoring request." ? 1 Answer
The REAL size of an object. 3 Answers
Resize object in runtime 1 Answer
Scale Issues. Heights, Mass and Cameras 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                