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
Static methods
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 |
---|
staticareaAttachObjectInstanceId(area:RID, id:UInt64):Void
Assigns the area to a descendant of godot.Object
, so it can exist in the node tree.
staticareaClearShapes(area:RID):Void
Removes all shapes from an area. It does not delete the shapes, so they can be reassigned later.
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.
staticareaGetObjectInstanceId(area:RID):UInt64
Gets the instance ID of the object the area is assigned to.
staticareaGetParam(area:RID, param:Physics2DServer_AreaParameter):Dynamic
Returns an area parameter value. See godot.Physics2DServer_AreaParameter
for a list of available parameters.
staticareaGetShapeTransform(area:RID, shapeIdx:Int):Transform2D
Returns the transform matrix of a shape within an area.
staticareaGetSpaceOverrideMode(area:RID):Physics2DServer_AreaSpaceOverrideMode
Returns the space override mode for the area.
staticareaRemoveShape(area:RID, shapeIdx:Int):Void
Removes a shape from an area. It does not delete the shape, so it can be reassigned later.
staticareaSetCollisionLayer(area:RID, layer:UInt):Void
Assigns the area to one or many physics layers.
staticareaSetCollisionMask(area:RID, mask:UInt):Void
Sets which physics layers the area will monitor.
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.
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.
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
.
staticareaSetShapeDisabled(area:RID, shapeIdx:Int, disabled:Bool):Void
Disables a given shape in an area.
staticareaSetShapeTransform(area:RID, shapeIdx:Int, transform:Transform2D):Void
Sets the transform matrix for an area shape.
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.
staticbodyAddCollisionException(body:RID, exceptedBody:RID):Void
Adds a body to the list of bodies exempt from collisions.
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.
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 |
---|
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.
staticbodyAttachObjectInstanceId(body:RID, id:UInt):Void
Assigns the area to a descendant of godot.Object
, so it can exist in the node tree.
staticbodyGetCollisionMask(body:RID):UInt
Returns the physics layer or layers a body can collide with.
staticbodyGetContinuousCollisionDetectionMode(body:RID):Physics2DServer_CCDMode
Returns the continuous collision detection mode.
staticbodyGetDirectState(body:RID):Physics2DDirectBodyState
Returns the godot.Physics2DDirectBodyState
of the body. Returns null
if the body is destroyed or removed from the physics space.
staticbodyGetMaxContactsReported(body:RID):Int
Returns the maximum contacts that can be reported. See godot.Physics2DServer.bodySetMaxContactsReported
.
staticbodyGetObjectInstanceId(body:RID):UInt
Gets the instance ID of the object the area is assigned to.
staticbodyGetParam(body:RID, param:Physics2DServer_BodyParameter):Single
Returns the value of a body parameter. See godot.Physics2DServer_BodyParameter
for a list of available parameters.
staticbodyGetShapeMetadata(body:RID, shapeIdx:Int):Dynamic
Returns the metadata of a shape of a body.
staticbodyGetShapeTransform(body:RID, shapeIdx:Int):Transform2D
Returns the transform matrix of a body shape.
staticbodyIsOmittingForceIntegration(body:RID):Bool
Returns whether a body uses a callback function to calculate its own physics (see godot.Physics2DServer.bodySetForceIntegrationCallback
).
staticbodyRemoveCollisionException(body:RID, exceptedBody:RID):Void
Removes a body from the list of bodies exempt from collisions.
staticbodyRemoveShape(body:RID, shapeIdx:Int):Void
Removes a shape from a body. The shape is not deleted, so it can be reused afterwards.
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.
staticbodySetCollisionLayer(body:RID, layer:UInt):Void
Sets the physics layer or layers a body belongs to.
staticbodySetCollisionMask(body:RID, mask:UInt):Void
Sets the physics layer or layers a body can collide with.
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.
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
).
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.
staticbodySetMode(body:RID, mode:Physics2DServer_BodyMode):Void
Sets the body mode using one of the godot.Physics2DServer_BodyMode
constants.
staticbodySetOmitForceIntegration(body:RID, enable:Bool):Void
Sets whether a body uses a callback function to calculate its own physics (see godot.Physics2DServer.bodySetForceIntegrationCallback
).
staticbodySetParam(body:RID, param:Physics2DServer_BodyParameter, value:Single):Void
Sets a body parameter. See godot.Physics2DServer_BodyParameter
for a list of available parameters.
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
.
staticbodySetShapeAsOneWayCollision(body:RID, shapeIdx:Int, enable:Bool, margin:Single):Void
Enables one way collision on body if enable
is true
.
staticbodySetShapeDisabled(body:RID, shapeIdx:Int, disabled:Bool):Void
Disables shape in body if disable
is true
.
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.
staticbodySetShapeTransform(body:RID, shapeIdx:Int, transform:Transform2D):Void
Sets the transform matrix for a body shape.
staticbodySetSpace(body:RID, space:RID):Void
Assigns a space to the body (see godot.Physics2DServer.spaceCreate
).
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.
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 { } |
---|
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.
staticdampedStringJointGetParam(joint:RID, param:Physics2DServer_DampedStringParam):Single
Returns the value of a damped spring joint parameter.
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.
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.
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.
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.
staticjointGetParam(joint:RID, param:Physics2DServer_JointParam):Single
Returns the value of a joint parameter.
staticjointGetType(joint:RID):Physics2DServer_JointType
Returns a joint's type (see godot.Physics2DServer_JointType
).
staticjointSetParam(joint:RID, param:Physics2DServer_JointParam, value:Single):Void
Sets a joint parameter. See godot.Physics2DServer_JointParam
for a list of available parameters.
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.
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
.
staticshapeGetType(shape:RID):Physics2DServer_ShapeType
Returns a shape's type (see godot.Physics2DServer_ShapeType
).
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
.
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
.
staticspaceGetDirectState(space:RID):Physics2DDirectSpaceState
Returns the state of a space, a godot.Physics2DDirectSpaceState
. This object can be used to make collision/intersection queries.
staticspaceGetParam(space:RID, param:Physics2DServer_SpaceParameter):Single
Returns the value of a space parameter.
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.
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.