Object
All objects in a Simulo scene, such as boxes, circles, polygons, etc, are known to the API as Objects.
An Object reference is typically obtained by:
- Getting it with
Scene:get_object
- Getting it with
Scene:get_all_objects
- Using
self
in a Component script
Fields
.id
Identifier for the object. Is a number.
Functions
Make sure to use :function()
and not .function()
, or you'll get an error
:destroy()
Destroys the object. This will remove it from the scene and destroy its components.
Example
self:destroy();
:is_destroyed()
Well? Is it?
:get_up_direction()
It's a Vec2. Guess what it is
:get_right_direction()
It's a Vec2. Guess what it is
:get_linear_velocity()
Returns the linear velocity of the object as a Vec2. Measured in meters per second.
Example
local linvel = self:get_linear_velocity();
:set_linear_velocity()
Sets the linear velocity of the object to a Vec2. Measured in meters per second.
Note that this will not behave realistically. You may want to use :apply_force_to_center
instead.
Example
self:set_linear_velocity(vec2(1, 1));
:get_angular_velocity()
Gets the angular velocity of the object as a number. Measured in radians per second.
Example
local angvel = self:get_angular_velocity();
:apply_force_to_center()
Applies a force to the center of mass.
Example
self:apply_force_to_center(vec2(1, 1));
:apply_force()
Applies a force to the object at a world point.
Example
self:apply_force(vec2(1, 1), vec2(100, 100));
:apply_torque()
Applies a torque to the object.
Example
self:apply_torque(100);
:apply_angular_impulse()
Applies an angular impulse to the object.
Example
self:apply_angular_impulse(100);
:apply_linear_impulse()
Applies a linear impulse to the object at a world point.
Example
self:apply_linear_impulse(vec2(1, 1), vec2(100, 100));
:apply_linear_impulse_to_center()
Applies a linear impulse to the object to the center of mass.
Example
self:apply_linear_impulse_to_center(vec2(1, 1));
:get_mass()
Gets the mass of the object as a number. Measured in uhh i forgot, check box2d docs
Example
local mass = self:get_mass();
:set_angular_velocity()
Sets the angular velocity of the object to a number. Measured in radians per second.
Example
self:set_angular_velocity(math.rad(10)); -- 10 degrees per second
:get_position()
Gets the position of the object as a number.
Example
local pos = self:get_position();
:get_pivot()
:set_angle rotates around it
:set_position()
Sets the position of the object to a number.
Example
self:set_position(vec2(100, 100));
:send_event()
Sends an event to the object, all its components, and all its attachments, and all components on those. Wow!
:get_angle()
Gets the angle of the object as a number. Measured in radians.
Example
local angle = self:get_angle();
:set_angle()
Sets the angle of the object to a number. Measured in radians.
Example
self:set_angle(math.rad(45)); -- 45 degrees
:get_direct_connected()
Gets all objects directly connected to this object by joints. For example, if you hinge together a bunch of boxes to make a rope, this only returns the previous and next box in the rope, not the entire rope. Insane
Phasers are considered to not be a connection in this context, and so are ignored by this.
Example
local objects = self:get_direct_connected();
:get_touching()
Gets all objects this object is touching.
Example
local objects = self:get_touching();
:get_sensed()
When called on a sensor, gets all objects it's currently overlapping.
Example
local objects = self:get_sensed();
:get_all_bolted()
Gets all objects connected to this object by bolts. For example, if you make a giant chain of stuff bolted together, this will return the entire chain, not just the stuff this object is directly bolted to.
Example
local objects = self:get_all_bolted();
:get_name()
Gets the name of the object as a string.
Example
local name = self:get_name();
:set_name()
Sets the name of the object to a string.
Example
self:set_name("Joe");
:get_color()
Gets the color of the object as a color.
Example
local color = self:get_color();
:set_color()
Sets the color of the object to a color.
Example
self:set_color(Color:rgb(1.0, 0.0, 0.0)); -- red
:get_z_index()
Gets the Z index of the object as a number.
Example
local z_index = self:get_z_index();
:set_z_index()
Tries to set the Z index of the object as a number. Returns false if it failed, true if it won. You should usually use the below functions instead.
Example
self:set_z_index(5);
:move_to_back()
Move to back, visually. Updates Z indices
Example
self:move_to_back();
:move_to_front()
Move to front, visually. Updates Z indices
Example
self:move_to_front();
:move_backward()
Move backward, visually. Updates Z indices
Example
self:move_backward();
:move_forward()
Move forward, visually. Updates Z indices
Example
self:move_forward();
:get_restitution()
Gets the restitution of the object as a number.
:set_restitution()
Sets the restitution of the object to a number.
:get_friction()
Gets the friction of the object as a number.
:set_friction()
Sets the friction of the object to a number.
:get_gravity_scale()
Gets the gravity scale of the object as a number.
:set_gravity_scale()
Sets the gravity scale of the object to a number.
:get_linear_damping()
Gets the linear damping of the object as a number.
:set_linear_damping()
Sets the linear damping of the object to a number.
:get_angular_damping()
Gets the angular damping of the object as a number.
:set_angular_damping()
Sets the angular damping of the object to a number.
:get_body_type()
Gets the body type of the object. It will be equal to BodyType.Dynamic
, BodyType.Static
, or BodyType.Kinematic
.
:set_body_type()
Sets the body type of the object. It can be BodyType.Dynamic
, BodyType.Static
, or BodyType.Kinematic
.
:get_ccd_enabled()
Gets whether continuous collision detection is enabled for the object.
:set_ccd_enabled()
Sets whether continuous collision detection is enabled for the object. It only applies when an object with CCD touches an object without CCD, so don't just enable it for everything. You should instead only put it on fast-moving objects, like bullets, ping-pong balls, etc.
:get_is_sensor()
Gets whether the object is a sensor. Sensors do not collide with other objects, but they still trigger collision events.
:get_is_awake()
Gets whether the object is awake. Awake objects are actively simulated.
:set_is_awake()
Sets whether the object is awake. Awake objects are actively simulated.
:get_angle_locked()
Gets whether the object is allowed to rotate from physics. You can still :set_angle
on it even when this is the case.
:set_angle_locked()
Sets whether the object is allowed to rotate from physics. You can still :set_angle
on it even when this is the case.
:get_density()
Gets the density of the object as a number.
:set_density()
Sets the density of the object to a number.
:get_local_point()
Get local point from a world one
:get_world_point()
Get world point from a local one
:get_components()
Gets a list of all the components attached to the object.
:get_joints()
Gets a list of all the joints attached to the object. You can use :get_type()
on them to see what kind of joint they are.
:get_hinges()
Gets a list of all the hinges attached to the object.
:get_bolts()
Gets a list of all the bolts attached to the object.
:get_phasers()
Gets a list of all the phasers attached to the object.
:get_springs()
Gets a list of all the springs attached to the object.
:get_fixed_joints()
Gets a list of all the fixed joints attached to the object.
:get_collision_layers()
Gets the list of collision layers this object is in.
:set_collision_layers()
Sets the list of collision layers this object is in.
:add_component()
Adds a component to the object. It will not be started immediately, but rather remain "sleeping" until the next step when the scene isn't paused. This is so we edit component values in right-click menus before the component is started.
Example
local component = self:add_component({ hash = "<Some hash>" });
local component = self:add_component({
hash = "<Some hash>",
-- optionally, we can pass data which it'll get in `on_start`.
saved_data = {
some_value = 10,
},
-- for Advanced Use we can also give a `properties` table, but its not always a good idea since you need to pass everything about the properties, like the id, name, input_type, value, settings etc
-- and so if you pass `properties`, you have to set all of them, or they'll be missing
-- so, if thats not what you want, you should instead do component:set_property after adding the component, like:
-- ```
-- local prop = component:get_property("some_property_id");
-- prop.value = 10;
-- component:set_property("some_property_id", prop);
-- ```
});
:get_type()
Returns "object"
.