Random Movement

Example Script: Random Movement

The example script, Random Movement (RandomMovement.cs), randomly moves a dynamic object around its starting position. Grab it from the download link at the end of this article.

Instructions

Here is a step-by-step guide to using the script:

  1. Download the script file from the download link at the end of this article.

  2. Follow the instructions provided in Working with scripts to upload the script and add it to an object.

  3. Open the object's Properties panel and go to the Script Settings section.

  4. On the properties panel, set IsDynamic to On.

  5. At the bottom of the object's properties panel is a Script Settings section. Upon looking at the Script Settings section for the Random Movement script, you will see a list of parameters which you can set for the object. Setting values for these parameters can help you set your object's behavior.

  6. Once you have finished setting the parameters for your object, your script is ready! Save and build your scene.

  7. If you want to verify that the script is running correctly, visit your scene once it has finished building.

Script parameters

The parameters for Random Movement.

Speed

Speed allows you to set the speed of an object. The higher the value, the faster the object moves.

However, keep in mind that the speed is affected by the mass of the object. Make sure that the speed of your object is proportional to its mass.

Chaos

Chaos affects how the object changes course when it is hit. The Chaos value should be set between 0.0 and 1.0. The higher it is, the more the object will change course.

Range

Range determines how far an object will go from their starting position before it goes back to that starting point. Range can be set at any value.

Creative Commons License

Have more questions? Join our Discord!

Last updated