Menu
Lumberyard
User Guide (Version 1.15)

Force Volume

This feature is in preview release and is subject to change.

You can use the Force Volume component to apply physical force to objects within a volume. A force will be applied each frame to any object within the bounds of the volume. For example, if an object moves into a sphere volume, the Force Volume component applies force to that object.

Note

The Force Volume component requires the Trigger Area and any of the Shape components.

Example

The following Force Volume component uses a Box Shape component to define its volume.


                Example image of the Force Volume component.

Force Volume Properties


                Force Volume component and its properties in
                    Lumberyard Editor.

See the following Force Volume properties.

Name Description

Visible

The Force Volume component always appears in the viewport, even if the entity is not selected.

Debug Forces

If selected, a debug line is drawn in game mode. The debug line displays the direction of the net force for each entity inside the volume.

Forces

Specifies the force type that acts in the volume.

You can add, remove, and specify multiple force types for the same component.

You can define a new force type in a gem, so that the force appears in the same drop-down menu for the Force Volume component. The following example defines a new force type.

Example

#include <LmbrCentral/Physics/ForceVolumeRequestBus.h> class ExampleForce : public Force { public: AZ_CLASS_ALLOCATOR(ExampleForce , AZ::SystemAllocator, 0); AZ_RTTI(ExampleForce , "{00000000-0000-0000-0000-000000000000}", Force); static void Reflect(AZ::ReflectContext* context); AZ::Vector3 CalculateForce(const EntityParams& entity, const VolumeParams& volume) override { return AZ::Vector3(0, 10, 0); } };

For more examples to configure EBus (event bus) functions with the Force Volume component , see the ForceVolumeForces.h file in the lumberyard_version\dev\Gems\LmbrCentral\Code\Source\Physics directory.

Example

The following script uses the request bus interface.

function Script:OnActivate() ForceVolumeRequestBus.Event.SetForceDirection(self.entityId, Vector3(0, 0, 1)); end

You can use the event bus interface to communicate with other components of your game. For more information, see Working with the Event Bus (EBus) System.

Force Types

You can specify the following force types for the Force Volume component.

Linear Damping Force

Applies a force in the opposite direction to an entity's velocity. For example, you can create a force that simulates a swamp or mud.

Properties

Name Description
Damping Amount of damping to apply. Specify 0 for no damping.

Ebus Request Bus Interface

Request Name Description Parameters Return Scriptable
GetDamping Returns the damping amount. Void Float Yes
SetDamping Sets the damping amount. Float Void Yes

Example

The following script uses the request bus interface.

function Script:OnActivate() LinearDampingForceRequestBus.Event.SetDamping(self.entityId, 1.0); end

Simple Drag Force

Applies a force that simulates air resistance. Larger and faster objects experience more drag. Objects are approximated as spheres.

Properties

Name Description
Volume Density

Density of the volume. Specify higher density to increase the drag force.

Ebus Request Bus Interface

Request Name Description Parameters Return Scriptable
GetDensity Returns the density of the volume. Void Float Yes
SetDensity Sets the density of the volume. Float Void Yes

Example

The following script uses the request bus interface.

function Script:OnActivate() SimpleDragForceRequestBus.Event.SetDensity(self.entityId, 0.1); end

Local Space Force

Applies a force in local space, relative to the volume's orientation. For example, you can create a force that simulates a hair dryer or a vacuum cleaner.

Properties

Name Description
Direction Direction of the force in the local space of the volume.
Magnitude Size of the force.

Ebus Request Bus Interface

Request Name Description Parameters Return Scriptable
GetDirection Returns the direction of the force in local space. Void Vector3 Yes
GetMagnitude Returns the magnitude of the force. Void Float Yes
SetDirection Sets the direction of the force in local space. Void Yes Yes
SetMagnitude Sets the magnitude of the force. Float Void Yes

Example

The following script uses the request bus interface.

function Script:OnActivate() LocalSpaceForceRequestBus.Event.SetMagnitude(self.entityId, 10.0); end

Spline Follow Force

Applies a force to make entities follow a spline. The force uses a proportional-derivative (PD) controller, which simulates a spring moving along a spline. For example, you can create a force that simulates a water slide.

Properties

Name Description
Damping Ratio Damping amount of the controller. A value of 1 extremely reduces the force applied.
Frequency Frequency of the controller.
Target Speed Approximate target speed to follow the spline.
Lookahead

A multiplier combined with the entity's velocity to extrapolate the position where the spline is sampled. This property is useful when the Target Speed property is set to a high value.

Ebus Request Bus Interface

Request Name Description Parameters Return Scriptable
GetDamping Returns the damping of the controller. Void Float Yes
GetFrequency Returns the frequency of the controller. Void Float Yes
GetLookAhead Returns the lookahead amount. Void Float Yes
GetTargetSpeed Returns the target speed. Void Float Yes
SetDamping Sets the damping of the controller. Float Void Yes
SetFrequency Sets the frequency of the controller. Float Void Yes
SetLookAhead Sets the lookahead amount. Float Void Yes
SetTargetSpeed Sets the target speed. Float Void Yes

Example

The following script uses the request bus interface.

function Script:OnActivate() SplineFollowForce.Event.SetDamping(self.entityId, 1.0); end

World Space Force

Applies a force in world space. World space forces do not take into account an object's orientation. For example, you can create force that simulates gravity.

Properties

Name Description
Direction Direction of the force in world space.
Magnitude Size of the force.

Ebus Request Bus Interface

Request Name Description Parameters Return Scriptable
GetDirection Returns the direction of the force in world space. Void Vector3 Yes
GetMagnitude Returns the magnitude of the force. Void Float Yes
SetDirection Sets the direction of the force in world space. Vector3 Void Yes
SetMagnitude Sets the magnitude of the force. Float Void Yes

Example

The following script uses the request bus interface.

function Script:OnActivate() WorldSpaceForceRequestBus.Event.SetMagnitude(self.entityId, 10.0); end

Point Force

Applies a force relative to the center of the volume. The size of the magnitude determines if the force is inward or outward. For example, you can create a force that simulates an explosion or a black hole.

Properties

Name Description
Magnitude

Size of the force.

Specify a positive value for an outward force.

Specify a negative value for an inward force.

Ebus Request Bus Interface

Request Name Description Parameters Return Scriptable
GetMagnitude

Returns the magnitude of the force.

Void Float Yes
SetMagnitude

Sets the magnitude of the force.

Float Void Yes

Example

The following script uses the request bus interface.

function Script:OnActivate() PointForceRequestBus.Event.SetMagnitude(self.entityId, 1.0); end