Translations of this page:



Rotate an object continually

This article was written for “UniVCI-0.15.”

Example data:

To run a process continually while a VCI is present, use “update” function.

For the rotary movement, use Quaternion.AngleAxis to make the object rotate around the specified axis.
In this example, use GetUp() function to make the rotation around Y-axis.

Reference: Quaternion.AngleAxis

1. Create a new GameObject and create a Cube as its child.
In this example, we named the GameObject “Rotation_VCI”, but it can be anything really.
Let's name the Cube “Cube.” Specify Y-axis value of the Cube to 1 so that it doesn't go through the floor.

2. Attach the “VCI Object” component on the GameObject,
and attach the “VCI SubItem” component on the Cube.
When doing this, a “RigidBody” component is also attached automatically.
As we won't be using gravity, turn off Use Gravity and turn on Is Kinematic.

3. 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.

local cube = vci.assets.GetTransform("Cube")	--Insert the name of the SubItem as a string
local rotSpeed = 1	--Rotation speed
function updateAll()
    if cube.IsMine then  -- Called only when you have the ownership of the cube
	cube.SetLocalRotation(Quaternion.AngleAxis( rotSpeed, cube.GetUp() ) * cube.GetLocalRotation())

For details of each component settings, see the image below.

en/vci/sample/update/no2.txt · Last modified: 2022/03/06 23:12 by Ramen

Page Tools