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

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").

Converts local coordinates to Block coordinate system.

Converts world coordinates to Block coordinate system.

Inherited from Object

Hide

Adds given Object as a child.

Object extensions like Shape or MutableShape are naturally accepted too.

By default, when using AddChild, the child maintains it's LocalPosition. But since the local position remains the same in the new parent, it means the child's world position may change.

The keepWorld optional parameter, false by default, can be used to maintain the child's Position (world position) instead.

It's also a good practice to set child/parent relationships before setting positions.

local o = Object()
local myShape = Shape(Items.someuser.someitem)
o:AddChild(myShape)

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()
nil GetChild ( integer index )

Get child Object at index.

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

Get Shape's parent.

print(myObject:GetParent())

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

By default, when using SetParent, the child maintains it's LocalPosition. But since the local position remains the same in the new parent, it means the child's world position may change.

The keepWorld optional parameter, false by default, can be used to maintain the child's Position (world position) instead.

It's also a good practice to set child/parent relationships before setting positions.

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

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

o:RemoveFromParent()

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)

Object:RotateLocal(number3) -- euler angles
Object:RotateLocal(number3, number) -- axis angle

Object:RotateWorld(number3) -- euler angles
Object:RotateWorld(number3, number) -- axis angle

Converts a local rotation to world coordinate system.

Converts a world rotation to local coordinate system.

Adds a text bubble at Object's position. For a Shape or Player, the text bubble will appear above its bounding box.

You may use a duration of -1 to set a permanent text bubble.

Returns true if the two Objects may collide with each other.

nil ApplyForce ( Object self, Number3 value )

Apply a force to Object, taking into account its Mass.

Instantaneously remove any ongoing text bubble.

Properties

Box BoundingBox read-only

The BoundingBox represents the bounds of the Shape. It is the limits of the Shape's blocks.

Number3 Center read-only

The coordinates of the center of the Shape's BoundingBox.

number Depth read-only

Returns Shape's depth, measured in cubes.

number Height read-only

Returns Shape's height, measured in cubes.

Number3 Max read-only

The coordinates of the max limit of the Shape's BoundingBox.

Number3 Min read-only

The coordinates of the min limit of the Shape's BoundingBox.

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)
number Width read-only

Returns Shape's width, measured in cubes.

Inherited from Object

Hide

Shape's constant acceleration in world coordinates per second squared.

⚠️ Acceleration will only affect Shape's position while Shape.Physics is true.

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

Collision groups the Shape belongs to.

⚠️ It doesn't mean the Shape will collide with other Objects in these groups.

If the Shape belongs to group number 3 for example, it means all Objects that have group number 3 in their Object.CollidesWithGroups property will collide with it.

By default:
- Objects collide with the Map and other Objects
- Players collide with the Map only

That can all be configured differently depening on your needs.

local object1 = Object()
local object2 = Object()
-- It's not mandatory to set Physics to true
-- An object with Physics set to false contributes to the
-- physics simulation as a static item (can't be moved)
object1.Physics = true
object2.Physics = true

-- making sure 2 objects collide with each other
-- NOTE: by default:
-- Map.CollisionGroups == {1},
-- Player.CollisionGroups == {2},
-- Object.CollisionGroups == {3}
object1.CollisionGroups = {5}
object2.CollisionGroups = {5}
object1.CollidesWithGroups = {1, 5} -- collides with Map + objects in group 5
object2.CollidesWithGroups = {1, 5} -- collides with Map + objects in group 5

-- would also work this way if you don't 
-- remember Map's group (which can be changed too by the way)
object1.CollidesWithGroups = Map.CollisionGroups + {5}

-- making an object collides with the Map and Players
local object = Object()
object.CollidesWithGroups = Map.CollisionGroups + Player.CollisionGroups

-- for Player (local player) to collide with other players and the Map
Player.CollidesWithGroups = Map.CollisionGroups + Player.CollisionGroups

Collision groups the Shape collides with.

By default:
- Objects collide with the Map and other Objects
- Players collide with the Map only

That can all be configured differently depening on your needs.

local object = Object()
-- It's not mandatory to set Physics to true
-- An object with Physics set to false contributes to the
-- physics simulation as a static item (can't be moved)
object.Physics = true

-- making an object collide with the Map and Players
object.CollidesWithGroups = Map.CollisionGroups + Player.CollisionGroups

-- for an Object to collide with other objects only
-- (won't collide with the map)
object.CollidesWithGroups = object.CollisionGroups

-- for Player (local player) to collide with other players and the Map
Player.CollidesWithGroups = Map.CollisionGroups + Player.CollisionGroups

-- making sure 2 objects collide with each others
-- NOTE: by default:
-- Map.CollisionGroups == {1},
-- Player.CollisionGroups == {2},
-- Object.CollisionGroups == {3}
local object1 = Object()
local object2 = Object()
object1.CollisionGroups = {5}
object2.CollisionGroups = {5}
object1.CollidesWithGroups = {1, 5} -- collides with Map + objects in group 5
object2.CollidesWithGroups = {1, 5} -- collides with Map + objects in group 5

-- would also work this way if you don't 
-- remember Map's group (which can be changed too by the way)
object1.CollidesWithGroups = Map.CollisionGroups + {5}

Turns physic simulation on/off when set.

⚠️ When turned off, Shape.Velocity & Shape.Motion are set to {0,0,0}.

nil by default. Can be set to a function that will be triggered when the Shape collides with another Object.

The function is called with 3 parameters: the object the callback was set for, the other actor in the collision and the Face of the first actor that's in contact.

Note: it's not necessary to do use all 3 parameters.

object.OnCollision = function(o1, o2)
  -- `o1` is `object` here
  print("collision detected between", o1, "and", o2)
end

object.OnCollision = function(o1, o2, face)
  -- `o1` is `object` here
  print("collision detected between", o1, "'s", face, "and", o2)
end

nil by default. Can be set to a function that will be triggered when the Shape ends colliding with another Object.

The function is called with 2 parameters: the object the callback was set for and the other actor in the collision.

object.OnCollisionEnd = function(o1, o2)
  -- `o1` is `object` here
  print("collision ended between", o1, "and", o2)
end

Executed when the Pointer is dragged (moved while down). Receives a PointerEvent parameter, just like Pointer.Drag.

(nil by default)

myObject.OnPointerDrag = function(pointerEvent)
  print("dx:", pointerEvent.DX, "dy:", pointerEvent.DY)
end

Position of the Shape in the world.

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

true when the Shape is not falling.

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

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.).

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 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

Tick is a function executed ~30 times per second when set (nil by default). Provides the Shape and elapsed time in seconds as parameters.

-- executed ~30 times per second on each user device
myObject.Tick = function(object, dt)
  print("elapsed:", dt, "seconds")
end

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.

Velocity of the Shape in world coordinates per second.

⚠️ Velocity will only affect Shape's position while Shape.Physics is true. Whenever it is set to false, Velocity is set to {0,0,0}.

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

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 an instantaneous displacement that contributes to moving Shape every frame, without changing Shape.Velocity directly.

Motion is expressed in world coordinates per second.

⚠️ Motion will only affect Shape's position while Shape.Physics is true. Whenever it is set to false, Motion is set to {0,0,0}.

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.

Scale of the Object, in its parent.

Nested Object local scales are combined to obtain the "world scale" (Object.LossyScale), the Object's final 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. Note that Objects that have multiple levels of nested rotations and scales will return a skewed lossy scale.

The mass of the Object determines how much a given force can move it and whether or not another object can be pushed by it. It cannot be zero, a neutral mass is a mass of 1.

The combined friction of 2 Objects in contact represents how much the moving Object will be able to slide along the colliding Object. It is a rate between 0 (full stop on contact) and 1 (full slide, no friction), values higher than 1 are allowed and will create an increasing momentum, like sliding on ice.

The combined bounciness of 2 Objects in contact represents how much of the moving Object's velocity is produced after being in contact with colliding Object, it is a rate between 0 (no bounce) and 1 (100% of the velocity bounced). Values higher than 1 are allowed and will create an increasing momentum at each bounce (try at your own risk).

All Objects have a collision box that represents the space occupied in the scene with regards to collisions. For Shapes and Players, the collision box is updated with their bounding box. For Objects, it is a 1-cube by default after physics was enabled for the first time.

Returns number of child Objects.

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.

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.

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.

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.

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.

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.