Skip to content

ShipAPI

TechTastic edited this page Sep 10, 2025 · 7 revisions

ShipAPI

I added a new API to computers placed on Ships to allow for greater access to Ship information! It will appear listed as both "ship" and as the Ship's name at the time of startup!

Functions

getWorldspacePosition

getWorldspacePosition() -> table

This method grabs the central position of a Ship in worldspace!

local pos = ship.getWorldspacePosition()
print("X: " .. pos.x)
print("Y: " .. pos.y)
print("Z: " .. pos.z)

getShipyardPosition

getShipyardPosition() -> table

This method grabs the central position of a Ship in the Shipyard!

local pos = ship.getShipyardPosition()
print("X: " .. pos.x)
print("Y: " .. pos.y)
print("Z: " .. pos.z)

getScale

getScale() -> table

This method grabs the scale of a Ship!

local scale = ship.getScale()
print("X Scale: " .. scale.x)
print("Y Scale: " .. scale.y)
print("Z Scale: " .. scale.z)

getQuaternion

getQuaternion() -> table

This method grabs the rotation of a Ship as a Quaternion! Note: This is meant to be used in conjuction with the Quaternion API!

local rot = ship.getQuaternion()
print(quaternion.new(vector.new(rot.x, rot.y, rot.z), rot.w)

getVelocity

getVelocity() -> table

This method grabs the linear velocity of a Ship!

local vel = ship.getVelocity()
print("X Velocity: " .. vel.x)
print("Y Velcoity: " .. vel.y)
print("Z Velocity: " .. vel.z)

getMass

geMass() -> number

This method grabs the mass of a Ship!

local mass = ship.getMass()
print("Mass: " .. mass)

getId

getId() -> number

This method grabs the ID of a Ship!

local id = ship.getId()
print("Ship ID: " .. id)

getOmega

getOmega() -> table

This method grabs the rotational velocity of a Ship!

local omega = ship.getOmega()
print("X: " .. omega.x)
print("Y: " .. omega.y)
print("Z: " .. omega.z)

isStatic

isStatic() -> boolean

This method tells whether a Ship is static!

local response = "No"
if ship.isStatic() then
    response = "Yes"
end
print("Is This Ship Static? " .. response)

getMomentOfInertiaTensor

getMomentOfInertiaTensor() -> table

This method grabs the moment of inertia tensor of a Ship as a 3x3 table!

local tensor = ship.getMomentOfInertiaTensor()
print("Moment of Inertia Tensor")
for i=1,3,1 do
    print(textutils.serialize(tensor[i]))
end

getTransformationMatrix

getTransformationMatrix() -> table

This method grabs the Ship to World Transformation Matrix as a 4x4 table!

local matrix = ship.getTransformationMatrix()
print("Transform Matrix")
for i=1,4,1 do
    print(textutils.serialize(matrix[i]))
end

getSize

getSize() -> table

This method grabs the size of a Ship!

local size = ship.getSize()
print("X: " .. size.x)
print("Y: " .. size.y)
print("Z: " .. size.z)

getSlug

getSlug() -> string

This method grabs the slug of a Ship!

local slug = ship.getSlug()
print("Ship Name: " .. slug)

setSlug

setSlug( string )

This method sets the slug of a Ship!

local name = ...
ship.setSlug(name)

transformPositionToWorld

transformPositionToWorld( vector ) -> table transformPositionToWorld( number, number, number ) -> table

This method transforms the given position (vector or x, y, z) to the Worldspace position using the given Ship!

local pos = vector.new(...)

local worldPos = ship.transformPositionToWorld(pos)
print("X: " .. worldPos.x)
print("Y: " .. worldPos.y)
print("Z: " .. worldPos.z)

getConstraints

getConstraints() -> table

This method gets all current contraints for the given Ship as a list!

local constraints = ship.getConstraints()
for id,con in pairs(constraints) do
    print("Constraint ID: " .. id)
    print("First Ship ID: " .. con.shipId0)
    print("Second Ship ID: " .. con.shipId1)
    print("Constraint Type: " .. con.type)
end

Clone this wiki locally