Skip to content

Lua API

TheHellBox edited this page Nov 6, 2018 · 4 revisions

World

Functions

  • CreateGameObject()

Creates a GameObjectBuilder.

example:

ent = World.CreateGameObject()
ent = ent:build()
  • GetAllObjects()

Returns a list of game objects.

example:

objects = World.GetAllObjects()
for k, v in ipairs(objects) do
	print(v:name())
end
  • GetGameObject(name)

Gets game object with specific name.

example:

ent = World.GetGameObject("player")
ent:set_position(0, 1, 0)
  • LoadModel(path, name)

Loads model from file

example:

World.LoadModel("./assets/models/yourmodel/model.obj", "my_model")
ent = World.CreateGameObject()
ent:with_model("my_model")
ent = ent:build()

GameObject

Functions

  • SetPosition(x, y, z)

Set position of the game object.

example:

ent = World.GetGameObject("player")
ent:SetPosition(0, 1, 0)
  • SetRotation(x, y, z)

Set rotation of the game object.(euler, radians)

example:

ent = World.GetGameObject("player")
ent:SetPosition(0, 3.14 / 2, 0)
  • Name()

Returns name of game object.

example:

ent = World.GetGameObject("player")
print(ent:Name()) -- Will print "player"
  • GetPosition()

Returns position of the game object

example:

ent = World.GetGameObject("player")
print(ent:GetPosition())
  • GetRotation()

Returns rotation of the game object(euler)

example:

ent = World.GetGameObject("player")
print(ent:GetRotation())
  • Direction(x, y, z) Returns direction of game object(forward, right, left, back, e.t.c)

example:

local dir = player_head:Direction(0, 0, 1) // gets forward direction
player_body:LookAt(-dir[1], 0.0, dir[3])
  • LookAt(x, y, z) Makes object to look at position

example:

local dir = player_head:Direction(0, 0, 1) // gets forward direction
player_body:LookAt(-dir[1], 0.0, dir[3])

GameObjectBuilder

Example

ent = World.CreateGameObject()
ent:with_position(0, 1, 0)
ent:with_name("player")
ent:with_model("cube")

ent:build()

Functions

  • with_name(name)
  • with_position(x, y, z)
  • with_model(name)
  • with_rotation(x, y, z, w)
  • build()
Clone this wiki locally