- Home /
Increase sprite falling speed
I have 2d prefab falling down with gravity. I want to increase falling speed of them randomly in runtime.
How can I do this in correct way? Changing Gravity Scale in runtime does make sense?
If you want them all to be falling at the same random speed then yes change your Gravity Scale at runtime. If you want them all to fall at different random speeds then disable gravity on the rigidbodys, then apply your own random gravity to each one ins$$anonymous$$d.
Thanks $$anonymous$$rSoad, I want to use first one of you are saying. This is works, I expected.
Answer by BobTheZealot · Oct 18, 2014 at 12:46 AM
Add a script to the prefab. I'm using C#. Script.cs: gameObject.transform.position.y-=Random.Range(minspeed,maxspeed);
gameObject.transform.position.y
accesses the prefab's y position, and decrease it randomly in a predefined range using Random.Range(minspeed,maxspeed);
The minimum speed and maximum speeds are both floats, so you have to add the letter F after the value.
Your answer
Follow this Question
Related Questions
Object Creation Speed incease 2 Answers
Change Sprite Pivot/Bounds from Script 2 Answers
runtime: script variable not processed as demanded 1 Answer
Is it possible to load Sliced Sprite (with .meta file) from OUTSIDE Packaged Data during runtime? 0 Answers
Loading and creating Sprites at runtime 0 Answers