Modding:ModGameObject
Jump to navigation
Jump to search
This content is a stub. You can help by expanding it.
There are several types of ModGameObjects that you can reference.
- Built-in GameObject - Built-in prefabs from Trailmakers, that we have made available to modders can be spawned.
- Custom Mesh - You can add custom meshes to your mod, and spawn those inside the game.
- Trigger - You can spawn Triggers used for checking if things enter/exit a specific area in the world.
- Players - You can get the ModGameObject of players
Spawning ModGameObject
There are various ways you can spawn objects depending on your need.
Example - Spawning a built-in object
You can get the list of built-in spawnable objects using
local spawn_name = "PFB_BARREL"
local spawn_position = tm.vector3.Create(0,0,0)
local barrel_obj = tm.physics.SpawnObject(spawn_position, spawn_name)
Example - Spawning a custom mesh with a custom texture
Assuming you have added a mesh.obj and texture.png to your mod folder.
local mesh_path = "mesh.obj"
local texture_path = "texture.png"
local mesh_key = "myMesh01"
local texture_key = "myTexture01"
local is_kinematic = True
local mass = 1000
local spawn_position = tm.vector3.Create(0,0,0)
tm.physics.AddMesh(mesh_path, mesh_key)
tm.physics.AddTexture(texture_path, texture_key)
local custom_obj = tm.physics.SpawnCustomObject(spawn_position, mesh_key, texture_key, is_kinematic, 1000)
Example - Spawning a trigger
local spawn_position = tm.vector3.Create(0,0,0)
local size = 10
local trigger_obj = tm.physics.SpawnBoxTrigger(spawn_position, size)
Despawning ModGameObject
Simple calling the reference to the ModGameObject with Despawn()
local spawn_name = "PFB_BARREL"
local spawn_position = tm.vector3.Create(0,0,0)
local barrelObj = tm.physics.SpawnObject(spawn_position, spawn_name)
barrelObj.Despawn()
Positioning of ModGameObject
ModGameObject has reference to
, meaning you can move, rotate and scale them. Example - Move a ModGameObject above a player
local barrel_obj = tm.physics.SpawnObject(tm.vector3.Create(0,0,0), "PFB_BARREL")
local player_position = tm.players.GetPlayerTransform(0).GetPosition()
barrel_obj.GetTransform().SetPosition(player_position + (tm.vector3.Up() * 2))