Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

PhysicsDirectSpaceState2D

繼承: Object

被繼承: PhysicsDirectSpaceState2DExtension

提供對 PhysicsServer2D 中物理空間的直接存取。

說明

Provides direct access to a physics space in the PhysicsServer2D. It's used mainly to do queries against objects and areas residing in a given space.

Note: This class is not meant to be instantiated directly. Use World2D.direct_space_state to get the world's physics 2D space state.

教學

方法

PackedFloat32Array

cast_motion(parameters: PhysicsShapeQueryParameters2D)

Array[Vector2]

collide_shape(parameters: PhysicsShapeQueryParameters2D, max_results: int = 32)

Dictionary

get_rest_info(parameters: PhysicsShapeQueryParameters2D)

Array[Dictionary]

intersect_point(parameters: PhysicsPointQueryParameters2D, max_results: int = 32)

Dictionary

intersect_ray(parameters: PhysicsRayQueryParameters2D)

Array[Dictionary]

intersect_shape(parameters: PhysicsShapeQueryParameters2D, max_results: int = 32)


方法說明

PackedFloat32Array cast_motion(parameters: PhysicsShapeQueryParameters2D) 🔗

檢查 Shape2D 能夠在不發生碰撞的情況下移動多遠。包括形狀和運動在內的所有查詢參數都通過 PhysicsShapeQueryParameters2D 物件提供。

返回包含該運動的安全和不安全比例(在 0 和 1 之間)的陣列。安全比例是該運動能夠不發生碰撞的最大分數。不安全比例是發生碰撞所需的最小分數。如果沒有偵測到碰撞,則返回的結果為 [1.0, 1.0]

注意:該形狀已碰撞的 Shape2D 會被忽略,例如形狀在其內部。請使用 collide_shape() 確定該形狀已碰撞的 Shape2D


Array[Vector2] collide_shape(parameters: PhysicsShapeQueryParameters2D, max_results: int = 32) 🔗

檢查通過 PhysicsShapeQueryParameters2D 物件給出的一個形狀與該空間的交點。結果陣列包含該形狀與另一個形狀相交處的點的列表。與 intersect_shape() 一樣,可以限制返回結果的數量以節省處理時間。

返回的點是接觸點對的一個列表。對於每一對,第一個是在 PhysicsShapeQueryParameters2D 對象中傳遞的形狀,第二個是來自物理空間的碰撞形狀。


Dictionary get_rest_info(parameters: PhysicsShapeQueryParameters2D) 🔗

Checks the intersections of a shape, given through a PhysicsShapeQueryParameters2D object, against the space. If it collides with more than one shape, the nearest one is selected. The returned object is a dictionary containing the following fields:

collider_id: The colliding object's ID.

linear_velocity: The colliding object's velocity Vector2. If the object is an Area2D, the result is (0, 0).

normal: The collision normal of the query shape at the intersection point, pointing away from the intersecting object.

point: The intersection point.

rid: The intersecting object's RID.

shape: The shape index of the colliding shape.

If the shape did not intersect anything, then an empty dictionary is returned instead.


Array[Dictionary] intersect_point(parameters: PhysicsPointQueryParameters2D, max_results: int = 32) 🔗

檢查點是否在任何實體形狀內。位置和其他參數通過 PhysicsPointQueryParameters2D 定義。點所在的形狀在包含具有以下欄位的字典的陣列中返回:

collider:碰撞對象。

collider_id:碰撞對象的 ID。

rid:相交對象的 RID

shape:碰撞形狀的形狀索引。

可以使用 max_results 參數限制相交的數量,以減少處理時間。

注意:Segments 建構模式下,ConcavePolygonShape2DCollisionPolygon2D 不是實體形狀。因此,它們不會被偵測到。


Dictionary intersect_ray(parameters: PhysicsRayQueryParameters2D) 🔗

與一個給定空間中的一個射線相交。射線位置和其他參數通過 PhysicsRayQueryParameters2D 定義。返回的物件是一個包含以下欄位的字典:

collider:該碰撞對象。

collider_id:該碰撞對象的 ID。

normal:在相交點處該對象的表面法線;如果射線從形狀內部開始,並且 PhysicsRayQueryParameters2D.hit_from_insidetrue,則為 Vector2(0, 0)

position:該相交點。

rid:該相交對象的 RID

shape:該碰撞形狀的形狀索引。

如果射線沒有與任何東西相交,則返回一個空字典。


Array[Dictionary] intersect_shape(parameters: PhysicsShapeQueryParameters2D, max_results: int = 32) 🔗

檢查通過 PhysicsShapeQueryParameters2D 物件給出的形狀與空間的交點。相交的形狀會以陣列的形式返回,該陣列包含有以下欄位的字典:

collider:碰撞對象。

collider_id:碰撞對象的 ID。

rid:相交對象的RID

shape:碰撞形狀的形狀索引。

可以使用 max_results 參數限制相交的數量,以減少處理時間。