Translations of this page:

Sidebar

en:vci:sample:update:no1

Move an object up and down continually


This article was written for “UniVCI-0.15.”

Example data:https://seed.online/items/d4866fb99ca08c1e983f25031bb4f2863b77a9b00823b9a94c3bd646b6d74284

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

For the up and down movement, let's use math.sin function to move the object smoothly.
As we don't have to synchronize this with other users, let's use FrameCount in “vci.me(ExportMe)(Local information).
“FrameCount” is the number of frames executed since the launch of the local client.

1. Create a new GameObject and create a Cube as its child.
In this example, we named the GameObject “Floating_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
-- Virtual Cast 1.5.1a
local cube = vci.assets.GetTransform("Cube")	--Insert the name of the SubItem as a string
local basePosition = cube.GetLocalPosition()	--The initial position of the Cube
local speed = 0.1	--speed
local range = 0.1	--move range
 
function updateAll() -- Virtual Cast 1.5.1a Called in all users regardless of the ownership
 
    if cube.IsMine then -- Virtual Cast 1.5.1a. The owner takes the responsibility to move the object
	local addPosition = Vector3.__new(0,math.sin(vci.me.FrameCount * speed * range),0)	--The position to add       
	cube.SetLocalPosition(basePosition + addPosition)
    end
end

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

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

Page Tools