the parent object this body is attached to
Optional
shapes: a initial shape, list of shapes, or JSON object defining the body
Optional
onBodyUpdate: Functioncallback for when the body is updated (e.g. add/remove shapes)
a reference to the parent object that contains this body, or undefined if it has not been added to one.
the body bouciness level when colliding with other solid bodies : a value of 0 will not bounce, a value of 1 will fully rebound.
The AABB bounds box reprensenting this body
define the collision type of the body for collision filtering
Readonly
fallingfalling state of the body
true if the object is falling
false if the object is standing on something
body force to apply to this the body in the current step. (any positive or negative force will be cancelled after every world/body update cycle)
<0,0>
Body.setMaxVelocity
// define a default maximum acceleration, initial force and friction
this.body.force.set(1, 0);
this.body.friction.set(0.4, 0);
this.body.setMaxVelocity(3, 15);
// apply a postive or negative force when pressing left of right key
update(dt) {
if (me.input.isKeyPressed("left")) {
this.body.force.x = -this.body.maxVel.x;
} else if (me.input.isKeyPressed("right")) {
this.body.force.x = this.body.maxVel.x;
}
}
body friction
The degree to which this body is affected by the world gravity
If true this body won't be affected by the world gravity
Readonly
isEither this body is a static body or not. A static body is completely fixed and can never change position or angle.
Readonly
jumpingjumping state of the body
equal true if the body is jumping
the body mass
max velocity (to limit body velocity)
The current velocity of the body. See to apply a force if you need to modify a body velocity
add the given vertices to the body shape
an array of me.Vector2d points defining a convex hull
Optional
index: number = 0the shape object for which to set the vertices
The forEach() method executes a provided function once per body shape element.
the callback function is invoked with three arguments:
fnction to execute on each element
Optional
thisArg: objectvalue to use as this(i.e reference Object) when executing callback.
add collision mesh based on a JSON object (this will also apply any physic properties defined in the given JSON file)
a JSON object as exported from a Physics Editor tool
Optional
id: stringan optional shape identifier within the given the json object
how many shapes were added to the body
https://www.codeandweb.com/physicseditor
// define the body based on the banana shape
this.body.fromJSON(me.loader.getJSON("shapesdef").banana);
// or ...
this.body.fromJSON(me.loader.getJSON("shapesdef"), "banana");
the built-in function to solve the collision response
the collision response object
Rotate this body (counter-clockwise) by the specified angle (in radians). Unless specified the body will be rotated around its center point
The angle to rotate (in radians)
Optional
v: Vector2d = ...an optional point to rotate around
Reference to this object for method chaining
By default all physic bodies are able to collide with all other bodies,
but it's also possible to specify 'collision filters' to provide a finer
control over which body can collide with each other.
Optional
bitmask: number = collision.types.ALL_OBJECTthe collision mask
collision.types
// filter collision detection with collision shapes, enemies and collectables
body.setCollisionMask(me.collision.types.WORLD_SHAPE | me.collision.types.ENEMY_OBJECT | me.collision.types.COLLECTABLE_OBJECT);
...
// disable collision detection with all other objects
body.setCollisionMask(me.collision.types.NO_OBJECT);
set the body vertices to the given one
an array of me.Vector2d points defining a convex hull
Optional
index: number = 0the shape object for which to set the vertices
Optional
clear: boolean = trueeither to reset the body definition before adding the new vertices
Protected
updateProtected
Updates the parent's position as well as computes the new body's velocity based
on the values of force/friction. Velocity chages are proportional to the
me.timer.tick value (which can be used to scale velocities). The approach to moving the
parent renderable is to compute new values of the Body.vel property then add them to
the parent.pos value thus changing the postion the amount of Body.vel each time the
update call is made.
Updates to Body.vel are bounded by maxVel (which defaults to viewport size if not set)
At this time a call to Body.Update does not call the onBodyUpdate callback that is listed in the constructor arguments.
true if resulting velocity is different than 0
a Generic Physic Body Object with some physic properties and behavior functionality, to add as a member of a Renderable.
See
Renderable.body