Main Content

Simulate Actor with Kinematics Properties Using Simulink

This example shows how to simulate an actor in Unreal Engine® simulation environment by setting kinematics properties using Simulink®. You build sphere and box actors to animate. To simulate an actor in Unreal Engine® simulation environment by setting kinematics properties using MATLAB®, see Simulate Actor with Kinematics Properties Using MATLAB.

First, you create a 3D environment using Simulation 3D Scene Configuration block and build the actors using Simulation 3D Actor blocks. Then, you set actor properties to enable mobility and set a view in the scene. Finally, you view the animation in the Simulation 3D Viewer window.

Open Model

Open the Simulink model.

open_system("AnimateActorWithKinematics");

Simulink model with two Simulation 3D Actor blocks named sphere and box and a Simulation 3D Scene Configuration block.

Explore Model Components

The model includes a Simulation 3D Actor block and a Simulation 3D Scene Configuration block. The Simulation 3D Scene Configuration block implements a 3D simulation environment. Double-click the Simulation 3D Scene Configuration block to open the Block Parameters Dialog Box. Set a view in the scene with the Scene view parameter. You can also set a custom viewpoint with this parameter. When building Simulink models with Simulation 3D Actor blocks, you must include the Simulation 3D Scene Configuration block.

Block parameter dialog box of Simulation 3D Scene Configuration block.

The Simulation 3D Actor block adds an actor to the 3D environment. Double-click the Simulation 3D Actor block to open the Block Parameters dialog box. To create an actor before simulation starts, on the Main tab, set Operation to Create at setup. The block first creates an empty actor with the name specified in the Actor name parameter. You can use any name for the actor. Then, the block loads the source file, if any is present, and runs the Initialization script. For more details, see Operating Modes.

The block parameter dialog box of the Simulation 3D Actor block named box shows parameters and initialization script

The Initialization script for the Sphere block builds a sphere shape and the Initialization script for the Box block builds a box shape for the actors. Each script sets a specific size using the createShape function. You can use the Properties of an actor object to set the Color and Mobility to make the actors movable. Specify the LinearVelocity value for the Sphere actor and AngularVelocity value for the Box actor to animate each actor at the specified value. On the Transform tab, you can also set the Initial position, Initial rotation and Actor scale for each actor.

Simulate Model

Simulate the model and view the animation of the sphere and box in the Simulation 3D Viewer.

sim("AnimateActorWithKinematics");

Sphere actor and box actor in the virtual world.

Close Model

Close the Simulink model.

close_system("AnimateActorWithKinematics");

See Also

|

Related Topics