Object

An Object is the most basic thing that can be added to the game 3D scene.

It has a position, a rotation and a scale and can contain child Objects, including Object extensions like Shape.

An object by itself does not render anything on screen, but it can contain Shapes and thus become a parent coordinate system for them.

An Object can also take part to the physic simulation when setting Object.Physics to true.

Constructors

Object ( )

Creates an Object.

local o = Object()
Map:AddChild(o) -- adds o to the Map (top level object in the game scene)

Functions

nil AddChild ( Object child )

Adds given Object as a child.

Object extensions like Shape or MutableShape are naturally accepted too.

local o = Object()
local myShape = Shape(Items.someuser.someitem)
o:AddChild(myShape)
nil GetChild ( integer index )

Get child Object at index.

if o.ChildrenCount > 0 then
  print(o:GetChild(1)) -- prints first child
end

Converts a local position to world coordinate system.

local p = Number3(1, 2, 3)
local pInWorldCoords = myObject:PositionLocalToWorld(p)

Converts a world position to local coordinate system.

local p = Number3(1, 2, 3)
local pInLocalCoords = myObject:PositionWorldToLocal(p)

Unsets parent/child relationship with child parameter. The child ends up being deleted if it has no other references.

o:RemoveChild(someChildObject)

Unsets parent/child relationship with all children. Individual children end up being deleted if they have no other references.

o:RemoveChildren()

Removes the Object from its parent. Doesn't do anything if the Object has no parent.

o:RemoveFromParent()

Converts a local rotation to world coordinate system.

Converts a world rotation to local coordinate system.

nil SetParent ( Object parent )

Sets parent/child relationship with parent parameter. nil can be used to remove the Object from its parent.

local o = Object()
o:SetParent(Map) -- o is now a child of the map
-- (Map is an extension of Object)

Properties

Object's continuous acceleration.

Default value: {0,0,0}.

⚠️ Acceleration is nil and can't be set if Object.Physics is false.

-- Acceleration can be used to compensate gravity: 
myObject.Acceleration = -Config.ConstantAcceleration
-- myObject's acceleration is now the invert of 
-- Config.ConstantAcceleration, cancelling it.

Backward is a unit vector (vector with a length of 1). It determines which direction is "backward" for the Object.

Setting it is a way to rotate the Object.

Returns number of child Objects.

Down is a unit vector (vector with a length of 1). It determines which direction is "down" for the Object.

Setting it is a way to rotate the Object.

Forward is a unit vector (vector with a length of 1). It determines which direction is "forward" for the Object.

Setting it is a way to rotate the Object.

Can be set to true for the Object to be hidden.
Nothing else changes, the Object remains in the scene and it keeps being affected by the simulation (collisions, etc.).

boolean IsOnGround read-only

true when the Object is not falling.

⚠️ IsOnGround only makes sense when Object.Physics is true.

Left is a unit vector (vector with a length of 1). It determines which direction is "left" for the Object.

Setting it is a way to rotate the Object.

Position of the Object in its parent.
In other words, LocalPosition refers to the position of the Object relative to the {0,0,0} position of its parent.

Rotation of the Object in its parent.

Nested Object local rotations are combined to obtain the "world rotation" (Object.Rotation), the Object's final on-screen rotation.

Scale of the Object, in its parent.

Nested Object local scales are combined to obtain the "world scale" (Object.Scale), the Object's final on-screen scale.

myObject.LocalScale = 2 -- the Object is now 2 times bigger
topLevelObject.LocalScale = 2
local o = Object()
o.LocalScale = 0.5
topLevelObject:AddChild(o) -- o becomes a child of topLevelObject
-- o ends up being displayed with a scale of 1
number LossyScale read-only

Convenience property that attempts to match the actual world scale as much as it can.

Be aware, this Motion property is a hack regarding laws of physics. (sorry Isaac)

But it's very practical to move objects without worrying about forces at play.

This is what's being used by default when you're moving around with your avatar (see Client.DirectionalPad). It's the reason why you can stop moving horizontally while in the air.

Basically, Motion is a constant velocity that's added to Object.Velocity each frame to obtain the final movement. (Object.Velocity value is not impacted)

Motion is expressed in world coordinates.

⚠️ Motion is nil and can't be set if Object.Physics is false.

local speed = 10
myObject.Motion = Camera.Forward * speed
-- myObject will move in the same direction the camera is currently facing.
-- If the Camera rotates after this, it won't change where myObject is heading.

Turns physic simulation on/off when set.

⚠️ When turned on, Object.Velocity & Object.Motion are set to {0,0,0}.

Position of the Object in the world.

local o = Object()
-- places the object where the local player is
o.Position = Player.Position

Right is a unit vector (vector with a length of 1). It determines which direction is "right" for the Object.

Setting it is a way to rotate the Object.

Rotation of the Object in the world (as seen on screen).

While it usually works for simple operations (like Rotation.X = Rotation.X + someAngle), we advise you to use Number3.Rotate to rotate an object around X, Y & Z axis.

You can also set unit vectors like Object.Up, Object.Right or Object.Forward to orient your object.

local o = Object()
o.Rotation = {0, math.pi, 0}
-- o revolved half a turn on Y axis

-- another way to rotate the object:
o.Forward:Rotate({0, 0, math.pi / 2})
o.Forward = Camera.Forward

Up is a unit vector (vector with a length of 1). It determines which direction is "up" for the Object.

Setting it is a way to rotate the Object.

Velocity of the Object in world coordinates.

⚠️ Velocity is nil and can't be set if Object.Physics is false.

-- makes myObject jump:
myObject.Velocity.Y = 100