The document defines several Lua functions and components for managing physics and transformations in objects. It includes methods for checking and retrieving components, enabling physics on objects, translating objects to new positions, and rotating them over time. The functions utilize coroutines for smooth transitions and error handling for missing components.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
3 views2 pages
Configurations - Unknwon File - Lua
The document defines several Lua functions and components for managing physics and transformations in objects. It includes methods for checking and retrieving components, enabling physics on objects, translating objects to new positions, and rotating them over time. The functions utilize coroutines for smooth transitions and error handling for missing components.
local components = obj.__components for i, component in pairs(components) do if component.name == c then return component end end return nil end
local function getcomponent(obj, c)
local components = obj.__components local result = {} for i, component in pairs(components) do if component.name == c then table.insert(result, component) end end return result end
local function getcomponents(obj, c)
local t = {} local components = obj.__components for i, component in pairs(components) do if component.name == c then table.insert(t, component) end end return t end
function PhysicsObject.SetEnabled(obj, state)
if not hascomponent(obj, "PhysicsObject") then return error( "Cannot set enabled state for object without a PhysicsObject component" ) end local comps = getcomponents(obj, "PhysicsObject") for _, c in pairs(comps) do c.enabled = state end end
function TransformController.TranslateTo(obj, pos, time)
if not hascomponent(obj, "TransformController") then return error( "Cannot translate object without a TransformController component" ) else local objpos = obj:position() local step = (pos - objpos) / (time * 100) -- Constant step size for i = 1, time * 100 do objpos = objpos + step -- Move by a fixed step each iteration obj:setPosition(objpos) end obj:setPosition(pos) -- Replicate TransformController end end
function TransformController.RotateBy(obj, rotation, time)
for i = 1, time * 100 do local r2 = r1 + step -- Move by a fixed step each iteration obj:setRotation(r2) -- Replicate TransformController r1 = r2 coroutine.yield() end