Character template: /flow_callbacks.lua — code sample - Stingray Lua API Reference

Character template: /flow_callbacks.lua — code sample

Code

ProjectFlowCallbacks = ProjectFlowCallbacks or {}

local PlayerUtil = require 'script/lua/util'
Actor = stingray.Actor
Vector3 = stingray.Vector3

-- Example custom project flow node callback. Prints a message.
-- The parameter t contains the node inputs, and node outputs can
-- be set on t. See documentation for details.
function ProjectFlowCallbacks.example(t)
    local message = t.Text or ""
    print("Example Node Message: " .. message)
end

function ProjectFlowCallbacks.add_random_impulse(t)
    local actor = t.actor
    local magnitude = t.magnitude
    local randomShiftDir = PlayerUtil.random_unit_vector3()

    if not magnitude then
        magnitude = 50
    end

    if not actor then
        return
    end

    randomShiftDir = Vector3.multiply(randomShiftDir, magnitude)
    Actor.add_impulse(actor, randomShiftDir)
end