The Snowball Effect

Hi, everyone! I am very new to Unity, even more so to coding in JavaScript and am having some issues. My group and I are trying to make a game where you play as a 2D Snowball that rolls down a hill, growing as it collides with the snowy ground. We have it set to where the snowball grows, but now it wont stop growing!

This is the code we have so far:

#pragma strict

function OnCollisionStay2D(other : Collision2D) {

if(other.gameObject.tag == “Ground”) {

transform.localScale += Vector3 (0.01, 0.01, 0.01)
}
}

We were looking into seeing if we could constrain the Transform so that once it reaches a certain size, it stops growing, but we havn’t had any luck there.

Thank you for your help in advance, I may add more as the project continues.

Thanks XD

So what your code is saying is simply: If this snowball is touching the ground, make it grow. Just thinking about it logically, what else needs to be happening for a snowball to grow? Yes, it has to be touching ground with snow on it, but it also needs to be moving.

1 Like

if (transform.localScale.x > 5){
transform.localScale = Vector3(5,5,5);
}

?

Thank you imaginaryhuman! It was exactly what we were looking for!

May you have an evening as awesome as you sir, I shall name my 1st born child after you.