EntityRigidbodyAddForceInPhysics - Create An Action That Adds Force To An Object
This guide provides instructions for setting up the EntityRigidbodyAddForceInPhysics action. In the sample app, once the avatar enters the blue trigger area, a force is applied to the sphere.
The sphere is not moving before the avatar enters the trigger area. | Once the avatar enters the trigger area, a force is applied to the sphere in the direction based on the parameters. |
1. In this example, a trigger is created and when the avatar or other objects enters the trigger area, an action adds force to an object. Any object can be used as a trigger, as long as the object has a Collision component. Because this specific example creates an empty area that the avatar and other objects can pass through, a simple 3D box is used. The entity does not have a RigidBody component added. Right-click in the Hierarchy and select New Entity > 3D > Box.
A. Click the "Add Component" button. Select Physics > Collision to add a Collision component.
B. Resize the collider to the desired size. In this example, the Half Extents field has been set to (2.5, .5, 2.5) for X, Y, Z.
C. The entity itself is currently set to Position (0, 0, 0) for X, Y, Z. In this example, the values for Position Offset are set to (0, -2, 0) for X, Y, Z to lower the collider to the ground.
D. Click the "EDIT VIVERSE EXTENSION" button to add the VIVERSE functionality.
2. To add the NotificationCenterPublish action functionality
A. Click the Select plugins text field and select TriggerAndAction in the dropdown menu.
B. Click "+" beside the Select a module and add dropdown.
C. Click "+" beside the selected module dropdown.
D. Click the type dropdown and select a desired trigger. In this example, the EntitySubscribeTriggerEnter trigger is selected.
E. Click "+" beside the selected module dropdown.
F. Click the type dropdown and select NotificationCenterPublish action in the dropdown menu.
G. Add a name for this notification in the notification name to publish field. In this example, the AddForce name is added.
3. In this example, the object receiving the notification is a simple sphere. Any object can be used to receive notifications. Because the sphere will have physics applied, Collision and RigidBody components are added. Right-click in the Hierarchy and select New Entity > 3D > Box.
A. Click the "Add Component" button. Select Physics > Collision to add a Collision component. Click the "Add Component" button again and select Physics > Rigid Body to add the RigidBody component.
B. Set the Type dropdown to Dynamic.
C. Click the "EDIT VIVERSE EXTENSION" button to add the VIVERSE functionality.
4. To add the NotificationCenterSubscribe trigger functionality
A. Click the Select plugins text field and select TriggerAndAction in the dropdown menu.
B. Click "+" beside the Select a module and add dropdown.
C. Click "+" beside the selected module dropdown.
D. Click the type dropdown and select the NotificationCenterSubscribe trigger.
E. In the notification name to publish field, add the same name that was used in the NoticationCenterPublish trigger. In this example, the AddForce name is added.
F. Click "+" beside the selected module dropdown.
G. Click the type dropdown and select EntityRigidbodyAddForceInPhysics action. Add a value to the x, y and z force fields.