Physics2DServer is the server responsible for all 2D physics. It can create many kinds of physics objects, but does not insert them on the node tree.

Static variables

@:native("Singleton")staticread onlySINGLETON:Object

Static methods

@:native("AreaAddShape")staticareaAddShape(area:RID, shape:RID, ?transform:Transform2D, ?disabled:Bool):Void

Adds a shape to the area, along with a transform matrix. Shapes are usually referenced by their index, so you should track which shape has a given index.

Parameters:

transform

If the parameter is null, then the default value is Transform2D.Identity

@:native("AreaAttachCanvasInstanceId")staticareaAttachCanvasInstanceId(area:RID, id:UInt64):Void

@:native("AreaAttachObjectInstanceId")staticareaAttachObjectInstanceId(area:RID, id:UInt64):Void

Assigns the area to a descendant of godot.Object, so it can exist in the node tree.

@:native("AreaClearShapes")staticareaClearShapes(area:RID):Void

Removes all shapes from an area. It does not delete the shapes, so they can be reassigned later.

@:native("AreaCreate")staticareaCreate():RID

Creates an godot.Area2D. After creating an godot.Area2D with this method, assign it to a space using godot.Physics2DServer.areaSetSpace to use the created godot.Area2D in the physics world.

@:native("AreaGetCanvasInstanceId")staticareaGetCanvasInstanceId(area:RID):UInt64

@:native("AreaGetObjectInstanceId")staticareaGetObjectInstanceId(area:RID):UInt64

Gets the instance ID of the object the area is assigned to.

@:native("AreaGetParam")staticareaGetParam(area:RID, param:Physics2DServer_AreaParameter):Dynamic

Returns an area parameter value. See godot.Physics2DServer_AreaParameter for a list of available parameters.

@:native("AreaGetShape")staticareaGetShape(area:RID, shapeIdx:Int):RID

Returns the godot.RID of the nth shape of an area.

@:native("AreaGetShapeCount")staticareaGetShapeCount(area:RID):Int

Returns the number of shapes assigned to an area.

@:native("AreaGetShapeTransform")staticareaGetShapeTransform(area:RID, shapeIdx:Int):Transform2D

Returns the transform matrix of a shape within an area.

@:native("AreaGetSpace")staticareaGetSpace(area:RID):RID

Returns the space assigned to the area.

@:native("AreaGetSpaceOverrideMode")staticareaGetSpaceOverrideMode(area:RID):Physics2DServer_AreaSpaceOverrideMode

Returns the space override mode for the area.

@:native("AreaGetTransform")staticareaGetTransform(area:RID):Transform2D

Returns the transform matrix for an area.

@:native("AreaRemoveShape")staticareaRemoveShape(area:RID, shapeIdx:Int):Void

Removes a shape from an area. It does not delete the shape, so it can be reassigned later.

@:native("AreaSetAreaMonitorCallback")staticareaSetAreaMonitorCallback(area:RID, receiver:Object, method:String):Void

@:native("AreaSetCollisionLayer")staticareaSetCollisionLayer(area:RID, layer:UInt):Void

Assigns the area to one or many physics layers.

@:native("AreaSetCollisionMask")staticareaSetCollisionMask(area:RID, mask:UInt):Void

Sets which physics layers the area will monitor.

@:native("AreaSetMonitorCallback")staticareaSetMonitorCallback(area:RID, receiver:Object, method:String):Void

Sets the function to call when any body/area enters or exits the area. This callback will be called for any object interacting with the area, and takes five parameters:

1: godot.Physics2DServer_AreaBodyStatus.added or godot.Physics2DServer_AreaBodyStatus.removed, depending on whether the object entered or exited the area.

2: godot.RID of the object that entered/exited the area.

3: Instance ID of the object that entered/exited the area.

4: The shape index of the object that entered/exited the area.

5: The shape index of the area where the object entered/exited.

@:native("AreaSetMonitorable")staticareaSetMonitorable(area:RID, monitorable:Bool):Void

@:native("AreaSetParam")staticareaSetParam(area:RID, param:Physics2DServer_AreaParameter, value:Dynamic):Void

Sets the value for an area parameter. See godot.Physics2DServer_AreaParameter for a list of available parameters.

@:native("AreaSetShape")staticareaSetShape(area:RID, shapeIdx:Int, shape:RID):Void

Substitutes a given area shape by another. The old shape is selected by its index, the new one by its godot.RID.

@:native("AreaSetShapeDisabled")staticareaSetShapeDisabled(area:RID, shapeIdx:Int, disabled:Bool):Void

Disables a given shape in an area.

@:native("AreaSetShapeTransform")staticareaSetShapeTransform(area:RID, shapeIdx:Int, transform:Transform2D):Void

Sets the transform matrix for an area shape.

@:native("AreaSetSpace")staticareaSetSpace(area:RID, space:RID):Void

Assigns a space to the area.

@:native("AreaSetSpaceOverrideMode")staticareaSetSpaceOverrideMode(area:RID, mode:Physics2DServer_AreaSpaceOverrideMode):Void

Sets the space override mode for the area. See godot.Physics2DServer_AreaSpaceOverrideMode for a list of available modes.

@:native("AreaSetTransform")staticareaSetTransform(area:RID, transform:Transform2D):Void

Sets the transform matrix for an area.

@:native("BodyAddCentralForce")staticbodyAddCentralForce(body:RID, force:Vector2):Void

@:native("BodyAddCollisionException")staticbodyAddCollisionException(body:RID, exceptedBody:RID):Void

Adds a body to the list of bodies exempt from collisions.

@:native("BodyAddForce")staticbodyAddForce(body:RID, offset:Vector2, force:Vector2):Void

Adds a positioned force to the applied force and torque. As with godot.Physics2DServer.bodyApplyImpulse, both the force and the offset from the body origin are in global coordinates. A force differs from an impulse in that, while the two are forces, the impulse clears itself after being applied.

@:native("BodyAddShape")staticbodyAddShape(body:RID, shape:RID, ?transform:Transform2D, ?disabled:Bool):Void

Adds a shape to the body, along with a transform matrix. Shapes are usually referenced by their index, so you should track which shape has a given index.

Parameters:

transform

If the parameter is null, then the default value is Transform2D.Identity

@:native("BodyAddTorque")staticbodyAddTorque(body:RID, torque:Single):Void

@:native("BodyApplyCentralImpulse")staticbodyApplyCentralImpulse(body:RID, impulse:Vector2):Void

@:native("BodyApplyImpulse")staticbodyApplyImpulse(body:RID, position:Vector2, impulse:Vector2):Void

Adds a positioned impulse to the applied force and torque. Both the force and the offset from the body origin are in global coordinates.

@:native("BodyApplyTorqueImpulse")staticbodyApplyTorqueImpulse(body:RID, impulse:Single):Void

@:native("BodyAttachCanvasInstanceId")staticbodyAttachCanvasInstanceId(body:RID, id:UInt):Void

@:native("BodyAttachObjectInstanceId")staticbodyAttachObjectInstanceId(body:RID, id:UInt):Void

Assigns the area to a descendant of godot.Object, so it can exist in the node tree.

@:native("BodyClearShapes")staticbodyClearShapes(body:RID):Void

Removes all shapes from a body.

@:native("BodyCreate")staticbodyCreate():RID

Creates a physics body.

@:native("BodyGetCanvasInstanceId")staticbodyGetCanvasInstanceId(body:RID):UInt

@:native("BodyGetCollisionLayer")staticbodyGetCollisionLayer(body:RID):UInt

Returns the physics layer or layers a body belongs to.

@:native("BodyGetCollisionMask")staticbodyGetCollisionMask(body:RID):UInt

Returns the physics layer or layers a body can collide with.

@:native("BodyGetContinuousCollisionDetectionMode")staticbodyGetContinuousCollisionDetectionMode(body:RID):Physics2DServer_CCDMode

Returns the continuous collision detection mode.

@:native("BodyGetDirectState")staticbodyGetDirectState(body:RID):Physics2DDirectBodyState

Returns the godot.Physics2DDirectBodyState of the body. Returns null if the body is destroyed or removed from the physics space.

@:native("BodyGetMaxContactsReported")staticbodyGetMaxContactsReported(body:RID):Int

Returns the maximum contacts that can be reported. See godot.Physics2DServer.bodySetMaxContactsReported.

@:native("BodyGetMode")staticbodyGetMode(body:RID):Physics2DServer_BodyMode

Returns the body mode.

@:native("BodyGetObjectInstanceId")staticbodyGetObjectInstanceId(body:RID):UInt

Gets the instance ID of the object the area is assigned to.

@:native("BodyGetParam")staticbodyGetParam(body:RID, param:Physics2DServer_BodyParameter):Single

Returns the value of a body parameter. See godot.Physics2DServer_BodyParameter for a list of available parameters.

@:native("BodyGetShape")staticbodyGetShape(body:RID, shapeIdx:Int):RID

Returns the godot.RID of the nth shape of a body.

@:native("BodyGetShapeCount")staticbodyGetShapeCount(body:RID):Int

Returns the number of shapes assigned to a body.

@:native("BodyGetShapeMetadata")staticbodyGetShapeMetadata(body:RID, shapeIdx:Int):Dynamic

Returns the metadata of a shape of a body.

@:native("BodyGetShapeTransform")staticbodyGetShapeTransform(body:RID, shapeIdx:Int):Transform2D

Returns the transform matrix of a body shape.

@:native("BodyGetSpace")staticbodyGetSpace(body:RID):RID

Returns the godot.RID of the space assigned to a body.

@:native("BodyGetState")staticbodyGetState(body:RID, state:Physics2DServer_BodyState):Dynamic

Returns a body state.

@:native("BodyIsOmittingForceIntegration")staticbodyIsOmittingForceIntegration(body:RID):Bool

Returns whether a body uses a callback function to calculate its own physics (see godot.Physics2DServer.bodySetForceIntegrationCallback).

@:native("BodyRemoveCollisionException")staticbodyRemoveCollisionException(body:RID, exceptedBody:RID):Void

Removes a body from the list of bodies exempt from collisions.

@:native("BodyRemoveShape")staticbodyRemoveShape(body:RID, shapeIdx:Int):Void

Removes a shape from a body. The shape is not deleted, so it can be reused afterwards.

@:native("BodySetAxisVelocity")staticbodySetAxisVelocity(body:RID, axisVelocity:Vector2):Void

Sets an axis velocity. The velocity in the given vector axis will be set as the given vector length. This is useful for jumping behavior.

@:native("BodySetCollisionLayer")staticbodySetCollisionLayer(body:RID, layer:UInt):Void

Sets the physics layer or layers a body belongs to.

@:native("BodySetCollisionMask")staticbodySetCollisionMask(body:RID, mask:UInt):Void

Sets the physics layer or layers a body can collide with.

@:native("BodySetContinuousCollisionDetectionMode")staticbodySetContinuousCollisionDetectionMode(body:RID, mode:Physics2DServer_CCDMode):Void

Sets the continuous collision detection mode using one of the godot.Physics2DServer_CCDMode constants.

Continuous collision detection tries to predict where a moving body will collide, instead of moving it and correcting its movement if it collided.

@:native("BodySetForceIntegrationCallback")staticbodySetForceIntegrationCallback(body:RID, receiver:Object, method:String, ?userdata:Dynamic):Void

Sets the function used to calculate physics for an object, if that object allows it (see godot.Physics2DServer.bodySetOmitForceIntegration).

@:native("BodySetMaxContactsReported")staticbodySetMaxContactsReported(body:RID, amount:Int):Void

Sets the maximum contacts to report. Bodies can keep a log of the contacts with other bodies, this is enabled by setting the maximum amount of contacts reported to a number greater than 0.

@:native("BodySetMode")staticbodySetMode(body:RID, mode:Physics2DServer_BodyMode):Void

Sets the body mode using one of the godot.Physics2DServer_BodyMode constants.

@:native("BodySetOmitForceIntegration")staticbodySetOmitForceIntegration(body:RID, enable:Bool):Void

Sets whether a body uses a callback function to calculate its own physics (see godot.Physics2DServer.bodySetForceIntegrationCallback).

@:native("BodySetParam")staticbodySetParam(body:RID, param:Physics2DServer_BodyParameter, value:Single):Void

Sets a body parameter. See godot.Physics2DServer_BodyParameter for a list of available parameters.

@:native("BodySetShape")staticbodySetShape(body:RID, shapeIdx:Int, shape:RID):Void

Substitutes a given body shape by another. The old shape is selected by its index, the new one by its godot.RID.

@:native("BodySetShapeAsOneWayCollision")staticbodySetShapeAsOneWayCollision(body:RID, shapeIdx:Int, enable:Bool, margin:Single):Void

Enables one way collision on body if enable is true.

@:native("BodySetShapeDisabled")staticbodySetShapeDisabled(body:RID, shapeIdx:Int, disabled:Bool):Void

Disables shape in body if disable is true.

@:native("BodySetShapeMetadata")staticbodySetShapeMetadata(body:RID, shapeIdx:Int, metadata:Dynamic):Void

Sets metadata of a shape within a body. This metadata is different from godot.Object.setMeta, and can be retrieved on shape queries.

@:native("BodySetShapeTransform")staticbodySetShapeTransform(body:RID, shapeIdx:Int, transform:Transform2D):Void

Sets the transform matrix for a body shape.

@:native("BodySetSpace")staticbodySetSpace(body:RID, space:RID):Void

Assigns a space to the body (see godot.Physics2DServer.spaceCreate).

@:native("BodySetState")staticbodySetState(body:RID, state:Physics2DServer_BodyState, value:Dynamic):Void

Sets a body state using one of the godot.Physics2DServer_BodyState constants.

Note that the method doesn't take effect immediately. The state will change on the next physics frame.

@:native("BodyTestMotion")staticbodyTestMotion(body:RID, from:Transform2D, motion:Vector2, infiniteInertia:Bool, ?margin:Single, ?result:Physics2DTestMotionResult, ?excludeRaycastShapes:Bool, ?exclude:Array):Bool

Returns true if a collision would result from moving in the given direction from a given point in space. Margin increases the size of the shapes involved in the collision detection. godot.Physics2DTestMotionResult can be passed to return additional information in.

Parameters:

exclude

If the parameter is null, then the default value is new Godot.Collections.Array { }

@:native("CapsuleShapeCreate")staticcapsuleShapeCreate():RID

@:native("CircleShapeCreate")staticcircleShapeCreate():RID

@:native("ConcavePolygonShapeCreate")staticconcavePolygonShapeCreate():RID

@:native("ConvexPolygonShapeCreate")staticconvexPolygonShapeCreate():RID

@:native("DampedSpringJointCreate")staticdampedSpringJointCreate(anchorA:Vector2, anchorB:Vector2, bodyA:RID, ?bodyB:RID):RID

Creates a damped spring joint between two bodies. If not specified, the second body is assumed to be the joint itself.

@:native("DampedStringJointGetParam")staticdampedStringJointGetParam(joint:RID, param:Physics2DServer_DampedStringParam):Single

Returns the value of a damped spring joint parameter.

@:native("DampedStringJointSetParam")staticdampedStringJointSetParam(joint:RID, param:Physics2DServer_DampedStringParam, value:Single):Void

Sets a damped spring joint parameter. See godot.Physics2DServer_DampedStringParam for a list of available parameters.

@:native("FreeRid")staticfreeRid(rid:RID):Void

Destroys any of the objects created by Physics2DServer. If the godot.RID passed is not one of the objects that can be created by Physics2DServer, an error will be sent to the console.

@:native("GetProcessInfo")staticgetProcessInfo(processInfo:Physics2DServer_ProcessInfo):Int

Returns information about the current state of the 2D physics engine. See godot.Physics2DServer_ProcessInfo for a list of available states.

@:native("GrooveJointCreate")staticgrooveJointCreate(groove1A:Vector2, groove2A:Vector2, anchorB:Vector2, ?bodyA:RID, ?bodyB:RID):RID

Creates a groove joint between two bodies. If not specified, the bodies are assumed to be the joint itself.

@:native("JointGetParam")staticjointGetParam(joint:RID, param:Physics2DServer_JointParam):Single

Returns the value of a joint parameter.

@:native("JointGetType")staticjointGetType(joint:RID):Physics2DServer_JointType

Returns a joint's type (see godot.Physics2DServer_JointType).

@:native("JointSetParam")staticjointSetParam(joint:RID, param:Physics2DServer_JointParam, value:Single):Void

Sets a joint parameter. See godot.Physics2DServer_JointParam for a list of available parameters.

@:native("LineShapeCreate")staticlineShapeCreate():RID

@:native("PinJointCreate")staticpinJointCreate(anchor:Vector2, bodyA:RID, ?bodyB:RID):RID

Creates a pin joint between two bodies. If not specified, the second body is assumed to be the joint itself.

@:native("RayShapeCreate")staticrayShapeCreate():RID

@:native("RectangleShapeCreate")staticrectangleShapeCreate():RID

@:native("SegmentShapeCreate")staticsegmentShapeCreate():RID

@:native("SetActive")staticsetActive(active:Bool):Void

Activates or deactivates the 2D physics engine.

@:native("SetCollisionIterations")staticsetCollisionIterations(iterations:Int):Void

Sets the amount of iterations for calculating velocities of colliding bodies. The greater the amount of iterations, the more accurate the collisions will be. However, a greater amount of iterations requires more CPU power, which can decrease performance. The default value is 8.

@:native("ShapeGetData")staticshapeGetData(shape:RID):Dynamic

Returns the shape data.

@:native("ShapeGetType")staticshapeGetType(shape:RID):Physics2DServer_ShapeType

Returns a shape's type (see godot.Physics2DServer_ShapeType).

@:native("ShapeSetData")staticshapeSetData(shape:RID, data:Dynamic):Void

Sets the shape data that defines its shape and size. The data to be passed depends on the kind of shape created godot.Physics2DServer.shapeGetType.

@:native("SpaceCreate")staticspaceCreate():RID

Creates a space. A space is a collection of parameters for the physics engine that can be assigned to an area or a body. It can be assigned to an area with godot.Physics2DServer.areaSetSpace, or to a body with godot.Physics2DServer.bodySetSpace.

@:native("SpaceGetDirectState")staticspaceGetDirectState(space:RID):Physics2DDirectSpaceState

Returns the state of a space, a godot.Physics2DDirectSpaceState. This object can be used to make collision/intersection queries.

@:native("SpaceGetParam")staticspaceGetParam(space:RID, param:Physics2DServer_SpaceParameter):Single

Returns the value of a space parameter.

@:native("SpaceIsActive")staticspaceIsActive(space:RID):Bool

Returns whether the space is active.

@:native("SpaceSetActive")staticspaceSetActive(space:RID, active:Bool):Void

Marks a space as active. It will not have an effect, unless it is assigned to an area or body.

@:native("SpaceSetParam")staticspaceSetParam(space:RID, param:Physics2DServer_SpaceParameter, value:Single):Void

Sets the value for a space parameter. See godot.Physics2DServer_SpaceParameter for a list of available parameters.