Main Content

Simulate Actor with Gravity Property Using Simulink

This example shows how to simulate an actor by enabling physics and gravity properties in the Unreal Engine® simulation environment using Simulink®. You build a ball to bounce from a plane. First, you create a world and set a view using Simulation 3D Scene Configuration block. Then, you create an actor using Simulation 3D Actor block and set the mobility. Finally, you view the animation in the Simulation 3D Viewer window. To simulate an actor by enabling physics and gravity properties in the Unreal Engine® simulation environment using MATLAB®, see Simulate Actor with Gravity Property Using MATLAB.

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

Open Model

Open the Simulink model.

open_system("AnimateBallWithGravity");

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

Explore Model Components

The model includes two Simulation 3D Actor blocks 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. You must include the configuration block when building Simulink models with Simulation 3D Actor blocks.

Block parameter dialog box of Simulation 3D Scene Configuration block

The Simulation 3D Actor blocks adds actors named Ball and Ground to the 3D environment. Double-click the Simulation 3D Actor block named Ball to open the Block Parameters dialog box. To create an actor before simulation starts, on the Main tab, set the Operation parameter 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 Initialization script builds a sphere shape for the actor using the createShape function. Specify the size and use the Properties of the actor object to set color of the actor. Set the properties Mobility, Gravity, and Physics to animate the actor.

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

Double-click the Simulation 3D Actor block named Ground to open the Block Parameters dialog box. Build a plane shape for the actor using the createShape function in the Initialization script text box. Specify the size and set the PreciseContacts property of the actor for accurate collision of the ball actor with the plane actor.

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

Simulate Model

Simulate the model and view the animation of a ball in the Simulation 3D Viewer.

sim("AnimateBallWithGravity");

Ball actor and plane actor in virtual world scene.

Close Model

Close the Simulink model.

close_system("AnimateBallWithGravity");

See Also

|

Related Topics