- Home /
I want gameobjects to move randomly on screen without overlapping.`
i have several gameobjects on which i have applied some texture.I want them to move randomly on screen without overlapping with each other i.e they should never collide and should acquire random positions on screen every time.
How about adding a behaviour that moves randomly which can also detect collisions and react accordingly?
How about looking at some of the basic features Unity offers? Like collisions. Those are one of the fundamental things Unity provides. Also, your objects will have a velocity vector, which will be defined at random, so if you want them to "go back in opposite directions" when they hit each other, then it's clearly just a case of detecting a collision and inverting the velocity (times the whole thing by -1). Seriously, this is really simple, and you could have easily solved this if you'd bothered doing any research first.
@Hoeloe : I did a lot of research before co$$anonymous$$g up with this question but i guess you didn't understood my question correctly that resulted in such absurd comment of yours.
I'm sorry but Hoeloe has a point.
Simply, create a script and attach it to all objects. I assume you have boundaries on screen, so when these objects hit each other or hit walls, they will go in opposite directions. Also I assume your game is 2d. in this script, you create a random vector and random speed. and these objects will move in this speed and direction vector. I don't know what kind of objects you have, let's say they are circles, then you should just implement a collision logic. you can do this in many ways, if you want this to happen as they are billiard balls, it would be a geometry problem, to find which direction each would go.
if you can explain what kind of objects you have and how they will react to collisions, you can get better help.
Answer by Key_Less · Apr 03, 2014 at 05:20 PM
I would suggest researching flocking algorithms. It will allow your objects to have decently random movements while avoiding collisions with each other. You can find some JS and C# script references here. But before jumping into the code, I'd recommend investigating how flocking is intended to work so you can have a better understanding of it's capabilities and uses.
Answer by HariKrishnan · Apr 02, 2014 at 10:03 AM
can you use waypoint concepts. to apply for each gameobject.
That would be good but not random.And that would be too tedious.