Sub
Name
Type
Description
Type
Description
-- entity.lua
local function init(self)
self.Physics = true
self.Data.mass = 1
local box_shape = api.physics.NewBoxShape(1, 1, 1)
local box = api.physics.NewBody(box_shape, self.Data.mass)
self.Body = box
self.Data.last_velocity = api.physics.NewVector(0,0,0)
end
local function update(self, dt)
local vector = api.physics.NewVector(
math.random()-0.5,
math.random()-0.5,
math.random()-0.5
)
local last_velocity = api.physics.NewVector(
self.Data.last_velocity.X,
self.Data.last_velocity.Y,
self.Data.last_velocity.Z
)
local difference = self.Body.Velocity:Sub(last_velocity)
self.Body:ApplyForce(vector)
if self.Data.mass == 1 then
print ("The entity body's Velocity has changed by", difference, ".")
end
self.Data.last_velocity = self.Body.Velocity
end
-- Turn on physics calculations for this entity.
-- Create a box shape and a body. Assign it to the entity.
-- Every update, apply a random force to the entity.
-- Subtract the entity's current velocity from its velocity in the previous update.
-- If the entity body's mass is 1, deduce the random force values of the previous update.
-- Prints:
-- The entity body's Velocity has changed by &{0 0 0} .
--[[ The entity body's Velocity has changed
by &{-0.0796297187387347 -0.20622464089421477 -0.3295008445210883} . ]]--
--[[ The entity body's Velocity has changed
by &{0.18629271371162615 -0.08334125314312901 -0.10271511976491188} . ]]--
-- ...Last updated