x


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!

more ▼

asked Nov 10 '11 at 08:34 AM

NickleKoch gravatar image

NickleKoch
1 2 3 3

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Nov 10 '11 at 10:13 AM

syclamoth gravatar image

syclamoth
14.8k 7 15 80

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1797
x1373
x575
x199

asked: Nov 10 '11 at 08:34 AM

Seen: 1013 times

Last Updated: Nov 10 '11 at 10:13 AM