Translations of this page:

Sidebar

en:vci:sample:update:no2

Rotate an object continually


This article was written for “UniVCI-0.15.”

Example data:https://seed.online/items/98bd2438ff0177cd18618c8b420a337a1496668209fcd18f614a58a5eedb8b3b

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
https://docs.unity3d.com/2018.4/Documentation/ScriptReference/Quaternion.AngleAxis.html

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.

main.lua
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())
    end
end

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