How to enable Kinetic Behavior
The steps to apply an external force to a 3D character are summarized below:
Create a Dynamic Action
Compute an external force
Apply the external force
Step 1. Create a Dynamic Action
To enable kinetic behavior on a game character, first create an instance of U4DEngine::U4DDynamicAction as shown on line 1. Then enable kinetic behavior on the dynamic action as shown on line 2. At this moment, the physics engine will be able to exert external forces on the model.
Step 2. Compute an External Force
Next, we need to compute the external force and apply it to the model using the method addForce(). The following snippet shows the process:
In line 8a we get the mass of the entity using the method getMass(). In line 8b, we set the desired velocity vector. In this instance, we want to velocity to be two units in the +x direction. Finally, in line 8c, we compute the force.
In line 9, we apply the force to the 3D entity using the method addForce().
Since we want a constant force, we set the initial velocity to zero as shown in line 10 using the method setVelocity().
(Optional) Remove Gravity Forces
To prevent entities from falling, the Untold Engine allows you to control the force of gravity through the method U4DEngine::U4DDynamicModel::setGravity(). If you want objects not to fall, the force of gravity must be set to zero.
Result
Helper Functions
Here are some code snippets for your reference:
This snippet applies the appropriate force by providing the desired magnitude of the final velocity as an argument.
Note that in this instance, it is required to provide a force direction.
Whereas this code snippet applies a force by providing the desired final velocity vector as an argument:
Last updated