Quantcast
Channel: Questions in topic: "mass"
Viewing all articles
Browse latest Browse all 157

shrinking objects

$
0
0
So this script makes the gameobject shrink at a rate i chose, along with the mass. but the problem is no matter how much mass i give an object, it will loose mass at the same speed. so like if i gave an object a mass of 10 and another object a mass of 100 , they would end up with a mass of 0 and a size of 0 at the same time. so what i want is if two objects both the same size but one with more mass . the one with more mass will shrink slower than the one with less mass 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(); 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; ShrinkBabyShrink(shrinkFactor, someVector, 3); } } void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "Death") { hasEntered = true; } } private void OnTriggerExit(Collider other) { hasEntered = false; }

Viewing all articles
Browse latest Browse all 157

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>