- Home /
Question by
SUPPEAR · Feb 08, 2015 at 12:44 AM ·
androidgameobjectmobileobjects
Make object move randomly 2D
Hello, I am trying to figure out how to make my object move randomly in a given space. On top of that, I want it that after around 20-30 seconds that the speed increases slightly and that the objects shrinks. All help is appreciated.
Comment
Answer by toddisarockstar · Feb 08, 2015 at 01:56 AM
Ha...sounds fun. this should do something for ya.
var randomspot:Vector2;
var speed:float;
var timer:float;
function Update () {
timer=timer-Time.deltaTime;
if(timer<1){timer=15;
randomspot=Vector2(Random.Range(5,50),Random.Range(5,50));}
transform.position = Vector2.MoveTowards(transform.position, randomspot,speed);
}
Answer by toddisarockstar · Feb 08, 2015 at 01:56 AM
// Widen the object by 0.1
transform.localScale += Vector3(0.1,0,0);
Your answer
![](https://koobas.hobune.stream/wayback/20220613182748im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Duplication Problem. Please help. 1 Answer
Expand object on touch? 1 Answer
Transform.LocalScale Script Problem. Please help. 2 Answers
Expand Object On Touch? Someone please help me 1 Answer
Destroy Object On Touch? 2D 1 Answer