- Home /
Grow objects
This script makes objects shrink. how can i make it so it makes objects grow instead?
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
targetScale and target$$anonymous$$ass need to be bigger than the start value.
Your answer
Follow this Question
Related Questions
What's the Rigidbody's gravity unit? 1 Answer
Shooting a cannonball. 6 Answers
Direction of rotation and ApplyForce 1 Answer
AddRelativeTorque not rotating 1 Answer
Simple colliding objects are updated a frame late. 0 Answers