This translation is older than the original page and might be outdated. See what has changed.
Translations of this page:



Create a billiard ball that rolls when hit by a cue

This article was written for “UniVCI-0.15.”

Example data:

We will be using “onCollisionEnter” as we will be executing the process when objects collide with each other.

Here are the settings for each object.
Set GroupIDs of all SubItem to the same number except 0.
(SubItems with the same number will always have their ownership held by a single user, which is required for proper physics calculation)

On the VCI Object component in the GameObject, set the Scripts Size as 1.
Enter “main.lua” in the Name and paste the script shown below.

AddForce(Vector3) applies a force of Vector3 to a object.

GetUp() gives you the up direction (local Y-direction) in a unit vector.
In this example, the direction toward the tip of the cue is the Y-direction.

function onCollisionEnter(item, hit)
    if (item=="bili_ball" and hit=="bili_q") or (item=="bili_q" and hit=="bili_ball") then
        local bili_ball = vci.assets.GetSubItem("bili_ball")
        local bili_q = vci.assets.GetSubItem("bili_q")
        bili_ball.AddForce(1000 * bili_q.GetUp())
en/vci/sample/oncollision/no2.txt · Last modified: 2019/07/09 12:07 by h-eguchi

Page Tools