- Home /
Moving rigidbodies at random
In my project I have a number of rigidbody spheres, which can be dragged by the mouse (drag body script). I was wondering if it is possible to make them move around the screen at random also. I have no character controller therefore, AI would not work for me. Any ideas? Thanks!
Answer by syclamoth · Nov 10, 2011 at 10:13 AM
How random do you want them to be moving? There are different levels of randomness that you could be using here. The simplest (and most chaotic) would simply be to use
rigidbody.AddForce(Random.insideUnitSphere * multiplier);
every FixedUpdate. However, you might want something a little bit less random- so instead change the rate of change every frame-
curForce += Random.insideUnitSphere * multiplier;
rigidbody.AddForce(rateOfChange);
Do you want your rigidbodies to be acting only in two dimensions? What about bouncing off the walls? Doing it this way will still allow the objects to bounce normally, so simple collisions should work.
Your answer
Follow this Question
Related Questions
How to make brownian motion of a RigidBody animal AI? 1 Answer
Rigidbody.AddForce and incorrect rotation 2 Answers
Move 3D rigidbody sphere in the direction of it's rotation, controlled by the mouse. 0 Answers
Sphere + rigidbody + character controller 1 Answer
Sphere fly's when I want it to jump 1 Answer