# Simulate Actors with Dissipative Properties Using MATLAB

This example shows how to use dissipative properties such as `Friction` `and` `Restitution` to simulate actors in the Unreal Engine® simulation environment using MATLAB®. You build five actors and set the physical properties of the actors. First, you create a world. Then, you build two box actors on a plane actor with different dynamic friction and two ball actors with a coefficient of restitution, and apply force to animate the actors. Then, you add the actors to the world and set a view in the scene. Finally, view the impact of the properties on the actor movement in the Simulation 3D Viewer window.

Unreal Engine® uses the physics engine to control actor motion and perform real-time physics calculations when the physics property of an actor is enabled.

In this example, you use the `sim3d.World` object and functions to create and view a 3D environment and the `sim3d.Actor` object and functions to build actors in 3D environment.

### Create World

Create a world scene.

`world = sim3d.World();`

### Build Actors

Instantiate actors named `Box1`, `Box2`, `Sphere1`, `Sphere2` and `Plane1`. Use the `createShape` function to build box sphere shapes of specific sizes for the actors. Set the `Mobility`, `Gravity`, `Force`, `Mass`, and `Physics` properties of the actors to react to physical forces.

Use the `createShape` function to build a box shape for the `Box1` actor and specify the size. Use the `sim3d.Actor` properties to set the `Mobility`, `Color`, and initial position. Set the `Friction` to `0.6`, apply a `Force` of `400` N in Y direction, and set `Mass` to `1` kg. Add actor to the world.

```box1 = sim3d.Actor('ActorName','Box1', 'Translation', [12,-6,0.5],... 'Mobility', sim3d.utils.MobilityTypes.Movable); box1.createShape('box', [2, 2, 2]); box1.Color = [1,0,0]; box1.Gravity = true; box1.Physics = true; box1.Friction = 0.6; box1.Mass = 1; box1.Force = [0 400 0]; world.add(box1);```

Use the `createShape` function to build a box shape for the `Box2` actor and specify the size. Use the `sim3d.Actor` properties to set the `Mobility`, `Color`, and initial position. Set the `Friction` to `0.2`, apply a `Force` of `400` N in Y direction, and set `Mass` to `1` kg. Add actor to the world.

```box2 = sim3d.Actor('ActorName','Box2', 'Translation', [8,-6,0.5],... 'Mobility', sim3d.utils.MobilityTypes.Movable); box2.createShape('box', [2, 2, 2]); box2.Color = [1,1,0]; box2.Gravity = true; box2.Physics=true; box2.Friction = 0.2; box2.Mass = 1; box2.Force = [0 400 0]; world.add(box2);```

Use the `createShape` function to build a sphere shape for the `Sphere1` actor and specify the size. Use the `sim3d.Actor` properties to set the `Mobility`, `Color`, and initial position. Set the `Restitution` to `1`, apply a `Force` of `60` N in Y direction, and set `Mass` to `1` kg. Add actor to the world.

```sphere1 = sim3d.Actor('ActorName', 'Sphere1', 'Translation', [2, -1.5, 3],... 'Mobility', sim3d.utils.MobilityTypes.Movable); sphere1.createShape('sphere', [1 1 1]); sphere1.Color = [1 1 0]; sphere1.Mass = 1; sphere1.Physics = true; sphere1.Restitution = 1; sphere1.Force = [0 60 0]; world.add(sphere1);```

Use the `createShape` function to build a sphere shape for the `Sphere2` actor and specify the size. Use the `sim3d.Actor` properties to set the `Mobility`, `Color`, and initial position. Set the `Restitution` to `1`, apply a `Force` of `-60` N in Y direction, and set `Mass` to `1` kg. Add actor to the world.

```sphere2 = sim3d.Actor('ActorName', 'Sphere2', 'Translation', [2, 1.5, 3],... 'Mobility', sim3d.utils.MobilityTypes.Movable); sphere2.createShape('sphere', [1 1 1]); sphere2.Color = [1 1 0]; sphere2.Mass = 1; sphere2.Physics = true; sphere2.Restitution = 1; sphere2.Force = [0 -60 0]; world.add(sphere2);```

Use the `createShape` function to build a box shape for the `Plane1` actor and specify the size. Use the `sim3d.Actor` properties to set the `Mobility`, `Physics`, `Friction`, and `Restitution`. Add actor to the world.

```plane1 = sim3d.Actor('ActorName','Plane1','Translation', [0,0,-1],... 'Mobility', sim3d.utils.MobilityTypes.Stationary); plane1.createShape('box', [40, 40, 1]); plane1.Friction = 0; plane1.Restitution = 1; world.add(plane1);```

### Set Viewer Window Point of View

If you do not create a viewport, then the point of view is set to 0, 0, 0, and you can use the keyboard shortcuts and mouse controls to navigate in the Simulation 3D Viewer window.

For this example, use the `createViewport` function to create a viewport with a single field, `Main`, that contains a `sim3d.sensors.MainCamera` object.

`world.createViewport();`

### Run Animation

Run the animation set for `10` seconds with a sample time of `0.01` seconds.

`run(world,0.02,10)`

### Delete World

Delete the world object.

`world.delete();`