Shape

Shape extends Object, adding functions and properties to it.

A Shape is an Object that carries and displays a set of Blocks.

Constructors

Shape ( Item item )

Creates a Shape with imported Item.

local myShape = Shape(Items.someuser.someitem)
myShape.Position = { Map.Width * 0.5, Map.Height, Map.Depth * 0.5 }
Map:AddChild(myShape) -- adds created shape in the map

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)

Converts Block coordinates to local coordinate system.

Converts Block coordinates to world coordinate system.

Block GetBlock ( Number3 coordinates )

Gets a Block from the Shape.
Returned Block is read-only because Shape is immutable, unlike MutableShape.
Returns nil if there is no Block at those coordinates (i. e. if it's "air").

nil GetChild ( integer index )

Get child Object at index.

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

Converts local coordinates to Block coordinate system.

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 Shape from its parent. Doesn't do anything if the Shape 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)

Converts world coordinates to Block coordinate system.

Properties

Shape's continuous acceleration.

Default value: {0,0,0}.

⚠️ Acceleration is nil and can't be set if Shape.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 Shape.

Setting it is a way to rotate the Shape.

Returns number of child Objects.

number Depth read-only

Returns Shape's depth, measured in cubes.

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

Setting it is a way to rotate the Shape.

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

Setting it is a way to rotate the Shape.

number Height read-only

Returns Shape's height, measured in cubes.

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

boolean IsOnGround read-only

true when the Shape is not falling.

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

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

Setting it is a way to rotate the Shape.

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

Rotation of the Shape 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 Shape.Velocity each frame to obtain the final movement. (Shape.Velocity value is not impacted)

Motion is expressed in world coordinates.

⚠️ Motion is nil and can't be set if Shape.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, Shape.Velocity & Shape.Motion are set to {0,0,0}.

Pivot is a point that you set as a way to specify what part of the Shape will be used when setting its Position.

A Shape rotates around this point. The Pivot point can be outside your shape.

Pivot coordinates are local to the Shape.

As a convenience, Pivot can be set to a Block, the Number3 value is then set to represent its center.

-- Anchor at the center of a 3x3x3 shape:
myShape.Anchor = {1.5, 1.5, 1.5}
-- same result:
myShape.Anchor = myShape:GetBlock(1,1,1)

Position of the Shape 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 Shape.

Setting it is a way to rotate the Shape.

Rotation of the Shape 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 Shape.Up, Shape.Right or Shape.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 Shape.

Setting it is a way to rotate the Shape.

Velocity of the Shape in world coordinates.

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

-- makes myObject jump:
myObject.Velocity.Y = 100
number Width read-only

Returns Shape's width, measured in cubes.