Character template: /util.lua code sample - Stingray Lua API Reference
-- cache off for readability and speed
local Util = Util or {}
local Vector3 = stingray.Vector3
local Actor = stingray.Actor
local Math = stingray.Math
function Util.add_random_impulse(actor)
local randomShiftDir = random_unit_vector3()
randomShiftDir = Vector3.multiply(randomShiftDir, 50)
Actor.add_impulse(actor, randomShiftDir)
end
-- return a random unit vector3
function Util.random_unit_vector3()
return Vector3.normalize(Vector3(Math.random() - 0.5, Math.random() - 0.5, Math.random() - 0.5))
end
return Util