AddForceToPrefabInstance(string prefabInstanceName, float forceX, float forceY, float forceZ, float forcePower)


This function applies force to the prefab instance that has dynamic physics. To view the name of prefab instances, open the VScene and click on the desired Prefab Instance in the “Prefabs and GUIs” section and press the Edit button. You can also access the names of prefab instances from the Script Utility section of the script editor ( Tools > Script Editor > Tools > Script Utility). In the dialog that appears, you can view and copy the name of the prefab instance.


Specifies the name of the prefab instance that has dynamic physics. You can also use the name “this” for this parameter. In this case, “this” refers to the prefab instance that this script is attached to.

forceX, forceY, forceZ
These three values determine the direction of the force that is applied to prefab instance. Vanda Engine normalizes the vector (forceX, forceY, forceZ).

Determines the strength of the force.

Example 1

function Init()
     AddForceToPrefabInstance("1_VandaEngine17-SamplePack1_f1_barrel", 1.0, 1.0, 1.0, 5.0)

function Update()

This function applies a force of 5.0 units in the normalized direction (1.0, 1.0, 1.0) to the “1_VandaEngine17-SamplePack1_f1_barrel” prefab instance.

Example 2

--name of the script is addforcetoprefabinstance2.lua

function Init()
     AddForceToPrefabInstance("this", 1.0, 0.0, 0.0, 4.0)

function Update()

If, in the Prefab Editor, you attach addforcetoprefabinstance2.lua script to a Prefab, then “this” parameter in the AddForceToPrefabInstance function will point to instances of that Prefab in current VScene. For example, if you have an Instance named instance1_a from a Prefab named to which this script is attached, “this” in AddForceToPrefabInstance function refers to the name instance1_a.
This function applies a force of 4.0 units in the normalized direction (1.0, 0.0, 0.0) to the current prefab instance.