allows you to move the creation
a conventional inertial engine consumes 1 battery and 1 gasoline per second, a creative one does not require fuel
can move unlimited masses at very high speeds
it can work in two modes. normal and raw
in normal mode, you are "magnetized" to the activation point and will return to it even if something moves you, and with the help of QWEW you can move the magnetization point
in raw mode, you just send pulses
component name - inertialEngine
methods:
- inertialEngine.setActive(state:boolean) - starts or stops the engine
- inertialEngine.isActive():boolean - returns the state set via setActive. returns true even if there are no resources to work with in order to find out the true state use: inertialEngine.isActive() and inertialEngine.isWorkAvailable()
- inertialEngine.isWorkAvailable():boolean - outputs true if the engine can work at the moment (there is enough fuel and batteries)
- inertialEngine.getAvailableBatteries():number - returns the number of batteries available to the engine
- inertialEngine.getAvailableGas():number - returns the amount of fuel available to the engine
- inertialEngine.addRotation(offset:vec3) - adds an angle in radians to the target angle of rotation of the engine
- inertialEngine.addPosition(offset:vec3) - adds a position in meters to the target position of the engine (the position is added taking into account the rotation, the target rotation angle is taken into account, not the real one)
- inertialEngine.addGlobalPosition(offset:vec3) - adds a position in meters to the target position of the engine (uses the world coordinate, does not take into account the actual and target rotation of the creation)
- inertialEngine.setStableMode(mode) - sets the stabilization mode (default 1) to a maximum of 4. this changes the stabilization force. set to 0 to disable stabilization:
0 - no stabilization
1 - small creation
2 - medium creation
3 - big creation
4 - very big creation
- inertialEngine.getStableMode() - returns the state set via setStableMode
- inertialEngine.getOffset():number - returns the distance in meters from the actual location to the target point. does not work in raw mode
- inertialEngine.setRawMovement(boolean) - sets the raw movement mode. in this mode, the "addPosition" method will not affect the position of the creation, and the movements will need to be carried out using the "raw_move" method
- inertialEngine.isRawMovement():boolean - returns the state set via setRawMovement
- inertialEngine.setGravity(number) - sets the local gravity for the inertialEngine that will run in rawmode. The default is 1 (The standard gravity of the game). minimum values -1 maximum 1
- inertialEngine.getGravity():number - returns the state set via setGravity
- inertialEngine.raw_rotation(vec3) - makes the rotation pulse relative to the current rotation. it cannot be called more than once per tick, the maximum value of the vector element is 8. Note that the momentum is multiplied by the mass of the creation
- inertialEngine.raw_globalRotation(vec3) - creates a rotation relative to the coordinates of the world. it cannot be called more than once per tick, the maximum value of the vector element is 8. Note that the momentum is multiplied by the mass of the creation
- inertialEngine.raw_move(vec3) - makes the pulse relative to the current rotation. it cannot be called more than once per tick, the maximum value of the vector element is 5. Note that the momentum is multiplied by the mass of the creation
- inertialEngine.raw_globalMove(vec3) - creates an impulse relative to the coordinates of the world. it cannot be called more than once per tick, the maximum value of the vector element is 5. Note that the momentum is multiplied by the mass of the creation
- inertialEngine.raw_rawMove(vec3, worldSpace:boolean) - alias on sm.physics.applyImpulse(self.shape.body, vec, worldSpace). available only on creative inertialEngine
- inertialEngine.raw_rawRotation(vec3, worldSpace:boolean) - alias on sm.physics.applyTorque(self.shape.body, vec, worldSpace). available only on creative inertialEngine
- inertialEngine.setSoundType(type:number) - sets the inertialEngine sound type:
0 - off
1 - standard sound
- inertialEngine.getSoundType():number - returns the current type of motor sound
--example in normal mode
local wasd = getComponent("wasd")
local inertialEngine = getComponent("inertialEngine")
inertialEngine.setActive(true)
inertialEngine.setRawMovement(false)
inertialEngine.setStableMode(1)
local speed = 1
local rotateSpeed = math.rad(5)
--------------------------
local function up()
inertialEngine.addPosition(sm.vec3.new(0, 0, speed))
end
local function down()
inertialEngine.addPosition(sm.vec3.new(0, 0, -speed))
end
local function forward()
inertialEngine.addPosition(sm.vec3.new(speed, 0, 0))
end
local function back()
inertialEngine.addPosition(sm.vec3.new(-speed, 0, 0))
end
local function left()
inertialEngine.addPosition(sm.vec3.new(0, speed, 0))
end
local function right()
inertialEngine.addPosition(sm.vec3.new(0, -speed, 0))
end
--------------------------
local function _up()
inertialEngine.addRotation(sm.vec3.new(0, -rotateSpeed, 0))
end
local function _down()
inertialEngine.addRotation(sm.vec3.new(0, rotateSpeed, 0))
end
local function _left()
inertialEngine.addRotation(sm.vec3.new(0, 0, rotateSpeed))
end
local function _right()
inertialEngine.addRotation(sm.vec3.new(0, 0, -rotateSpeed))
end
--------------------------
local engineStop = false
function callback_loop()
if _endtick or engineStop then
inertialEngine.setActive(false)
return
end
if inertialEngine.getOffset() > 15 then --if the target position is further from the real one by more than 15 meters, it can be concluded that a collision has occurred and it is worth turning off the engine
inertialEngine.setActive(false)
engineStop = true
return
end
if wasd.isSeated() then
forward()
end
if wasd.isW() then
_up()
elseif wasd.isS() then
_down()
end
if wasd.isA() then
_left()
elseif wasd.isD() then
_right()
end
end