en:vci:sample:input:sample1

Table of Contents

Create a VCI that moves/scales/rotates with keyboard input

Move, rotate and scale a VCI using inputs from keyboard.

Example data

Component setting

You do not need components other than the SubItem component.
In the example below, you need a SubItem called “Target.”

VCI script

main.lua
local _Target = vci.assets.GetSubItem("Target")
 
function update()
 
    -- Get the axis input.
    local axis = vci.me.GetAxisInput()
 
    -- Input log
    if axis.x ~= 0 then
        print(" X : "..tostring(axis.x))
    end
 
    if axis.y ~= 0 then
        print(" Y : "..tostring(axis.y))
    end
 
    if axis.z ~= 0 then
        print(" Z : "..tostring(axis.z))
    end
 
    -- Move the Target
    local pos = 0.01 * axis + _Target.GetLocalPosition()
    _Target.SetLocalPosition(pos)
 
    -- Get input
    if  vci.me.GetButtonInput(1) then
        print(" Button1 pushed")
        -- Process rotation
        local rot = _Target.GetLocalRotation()
        rot = rot * Quaternion.AngleAxis(-30, Vector3.forward)
        _Target.SetLocalRotation(rot)
    end
 
    -- Get input
    if  vci.me.GetButtonInput(2) then
        print(" Button2 pushed")
        -- Process rotation
        local rot = _Target.GetLocalRotation()
        rot = rot * Quaternion.AngleAxis(30, Vector3.forward)
        _Target.SetLocalRotation(rot)
    end
 
    -- Get input
    if  vci.me.GetButtonInput(3) then
        print(" Button3 pushed")
        -- Process scale
        local scale = _Target.GetLocalScale()
        if scale.x < 0.2 then
            return
        end
        scale = scale + Vector3.__new(-0.1, -0.1, -0.1)
        _Target.SetLocalScale(scale)
    end
 
    -- Get input
    if  vci.me.GetButtonInput(4) then
        print(" Button4 pushed")
        -- Process scale
        local scale = _Target.GetLocalScale()
        scale = scale + Vector3.__new(0.2, 0.2, 0.2)
        _Target.SetLocalScale(scale)
    end
 
end

Move in XZ direction with keyboard, upward and downward with UI, rotate with 12 and scale with 34.


VCI Script (Description)

    -- Get the axis input.
    local axis = vci.me.GetAxisInput()
 
    -- Input log
    if axis.x ~= 0 then
        print(" X : "..tostring(axis.x))
    end

GetAxis always has the value of the state when pushed.
You can use it as is when moving things, but to show it on consoles, it is recommended not to display it when the value is 0.

en/vci/sample/input/sample1.txt · Last modified: 2023/05/11 20:30 by pastatto

Page Tools