CreateEntity

From OxeyeWiki

Jump to: navigation, search

physics:createEntity(bodyDefinition, x, y)

Creates and adds a new physics body to the physics object.

Parameter Expected Type Description
bodyDefinition A table The body definition table, see below.
x A number The entity's center X coordinate in world space, counted in meters.
y A number The entity's center Y coordinate in world space, counted in meters.
Returns

Returns the body identifier number (an integer). If something went horribly wrong (like, incorrect number of parameters), this method returns -1.

Daisymoon Physics Lib

Body Definition Table

The body definition table holds entity settings.

Parameter Expected Type Description
linearDamping A number How much the entity's linear velocity should be dampened. You can use this to simulate air friction. Defaults to 0.
angularDamping A number How much the entity's angular speed should be dampened. You can use this to simulate friction. Defaults to 0.
fixedRotation A boolean Set this to true if the entity isn't allowed to rotate at all. Defaults to false.
isBullet A boolean Enables Box2D's special "bullet" physics. Defaults to false.
allowSleep A boolean Set this to false if the entity is never allowed to enter sleeping state. This occurs if the entity is non-moving for a certain amount of time. Defaults to true.

Example


   local playerBodyDef = {
      linearDamping = 10,
      angularDamping = 1.5,
      fixedRotation = false,
      isBullet = false,
      allowSleep = false,
   }
   player.body = physics:createEntity(playerBodyDef, player.x * physResolution, player.y * physResolution)

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox