- Home /
How can I make a object get bigger as it falls?
Hi,
I am making a 2D webplayer game at the moment and have some cubes generated by code and would like to know how to A. Make it get bigger as it falls (with gravity) and B. Put an image on it.
Here's the code im using to spawn the cubes.
var myPrefab : Rigidbody2D;
var distanceMultiplier : float = 2;
function Start(){
var i : int = 0;
var pos : Vector3 = transform.position;
for(i=0; i<=250; i++){
Instantiate(myPrefab, Vector3(pos.x, pos.y+1.5, pos.z), transform.rotation);
yield WaitForSeconds(1);
Debug.Log("made ball "+i);
}
}
Thanks in advance, Nathan
Well you have the spawn point of the object. You can calculate the distance to the spawn point and multiply the transform.scale with it but this way it gets pretty big bretty fast. $$anonymous$$aybe another multiplication with a value between 0 and 1 would help you to achieve the wished effect.
Answer by Kiwasi · Jun 11, 2014 at 08:59 AM
You need to set transform.localScale based on transform.position.y
Code to try (C#):
void Update (){
float y = transform.position.y;
transform.localScale = new Vector3 (y,y,y);
}
Of course you will have to manipulate y to match your scenario
Your answer
Follow this Question
Related Questions
How to turn off gravity? 4 Answers
Scrolling and Looping 2D Background Image 1 Answer
Display a 2D image over my 3D scene 1 Answer
How to track transform.position in real time? 1 Answer
2d planetary gravity 3 Answers