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.
Checking the stable version of the documentation...
PhysicsDirectSpaceState3D
繼承: Object
被繼承: PhysicsDirectSpaceState3DExtension
提供對 PhysicsServer3D 中物理空間的直接存取。
說明
提供對 PhysicsServer3D 中物理空間的直接存取。主要用於對駐留在給定空間中的物件和區域進行查詢。
注意:該類不應直接實例化。請使用 World3D.direct_space_state 取得世界的 3D 物理空間狀態。
教學
方法
方法說明
PackedFloat32Array cast_motion(parameters: PhysicsShapeQueryParameters3D) 🔗
檢查 Shape3D 能夠在不發生碰撞的情況下移動多遠。包括形狀和運動在內的所有查詢參數都通過 PhysicsShapeQueryParameters3D 物件提供。
回傳包含該運動的安全和不安全比例(在 0 和 1 之間)的陣列。安全比例是該運動能夠不發生碰撞的最大分數。不安全比例是發生碰撞所需的最小分數。如果沒有檢測到碰撞,則回傳的結果為 [1.0, 1.0]。
注意:該形狀已碰撞的 Shape3D 會被忽略,例如形狀在其內部。請使用 collide_shape() 確定該形狀已碰撞的 Shape3D。
bool cast_motion_into(parameters: PhysicsShapeQueryParameters3D, result: PhysicsCastMotionResult3D) 🔗
Checks how far a Shape3D can move without colliding. All the parameters for the query, including the shape and the motion, are supplied through a PhysicsShapeQueryParameters3D object.
If the query is successful, this method returns true and writes the motion results into the PhysicsCastMotionResult3D object passed in result. If no collision occurs, it returns false.
Note: Any Shape3Ds that the shape is already colliding with e.g. inside of, will be ignored. Use collide_shape_into() to determine the Shape3Ds that the shape is already colliding with.
Array[Vector3] collide_shape(parameters: PhysicsShapeQueryParameters3D, max_results: int = 32) 🔗
檢查通過 PhysicsShapeQueryParameters3D 物件給出的一個形狀與該空間的交點。結果陣列包含該形狀與另一個形狀相交處的點的列表。與 intersect_shape() 一樣,可以限制返回結果的數量以節省處理時間。
返回的點是接觸點對的一個列表。對於每一對,第一個是在 PhysicsShapeQueryParameters3D 對象中傳遞的形狀,第二個是來自物理空間的碰撞形狀。
注意:該方法不考慮物件的 motion 屬性。
bool collide_shape_into(parameters: PhysicsShapeQueryParameters3D, result: PhysicsCollideShapeResult3D) 🔗
Checks the intersections of a shape, given through a PhysicsShapeQueryParameters3D object, against the space.
If intersections are found, this method returns true and writes the collision points into the PhysicsCollideShapeResult3D object passed in result. If no intersections are found, it returns false.
The number of returned results can be limited using PhysicsCollideShapeResult3D.max_collisions, to reduce the processing time.
Note: This method does not take into account the motion property of the object.
Dictionary get_rest_info(parameters: PhysicsShapeQueryParameters3D) 🔗
檢查通過 PhysicsShapeQueryParameters3D 物件給出的形狀與該空間的交點。如果它與多個形狀發生碰撞,則選擇最近的一個。回傳的物件是一個包含以下欄位的字典:
collider_id:該碰撞物件的 ID。
linear_velocity:該碰撞物件的速度 Vector3。如果物件是一個 Area3D,則結果為 (0, 0, 0)。
normal:相交點處查詢形狀的碰撞法線,法線指向遠離相交物件的方向。
point:相交點。
rid:該相交物件的 RID。
shape:該碰撞形狀的形狀索引。
如果該形狀沒有與任何東西相交,則回傳一個空字典。
注意:該方法不考慮物件的 motion 屬性。
bool get_rest_info_into(parameters: PhysicsShapeQueryParameters3D, result: PhysicsGetRestInfoResult3D) 🔗
Checks the intersections of a shape, given through a PhysicsShapeQueryParameters3D object, against the space.
If the shape collides with one or more shapes, this method returns true and writes the nearest collision information into the PhysicsGetRestInfoResult3D object passed in result. If no collisions occur, it returns false.
Note: This method does not take into account the motion property of the object.
Array[Dictionary] intersect_point(parameters: PhysicsPointQueryParameters3D, max_results: int = 32) 🔗
檢查點是否在任何實體形狀內。位置和其他參數通過 PhysicsPointQueryParameters3D 定義。點所在的形狀會以陣列的形式返回,該陣列包含有以下欄位的字典:
collider:碰撞對象。
collider_id:碰撞對象的 ID。
rid:相交對象的RID。
shape:碰撞形狀的形狀索引。
可以使用 max_results 參數限制相交的數量,以減少處理時間。
bool intersect_point_into(parameters: PhysicsPointQueryParameters3D, result: PhysicsIntersectPointResult3D) 🔗
Checks whether a point is inside any solid shape. Position and other parameters are defined through PhysicsPointQueryParameters3D.
If one or more shapes overlap the point, this method returns true and writes the intersection data into the PhysicsIntersectPointResult3D object passed in result. If no intersections are found, it returns false.
The number of intersections can be limited using PhysicsIntersectPointResult3D.max_intersections, to reduce the processing time.
Dictionary intersect_ray(parameters: PhysicsRayQueryParameters3D) 🔗
在給定空間中偵測與射線的相交情況。射線的位置和其他參數由 PhysicsRayQueryParameters3D 定義。返回的物件是包含以下欄位的字典:
collider:碰撞到的對象。
collider_id:碰撞到的對象的 ID。
normal:該物件表面交點處的法線,如果射線中該形狀的內部開始,並且 PhysicsRayQueryParameters3D.hit_from_inside 為 true,則為 Vector3(0, 0, 0)。
position:交點。
face_index:交點處的面索引。
注意:只有相交形狀是 ConcavePolygonShape3D 時才會返回有效值。否則返回 -1。
rid:相交對象的 RID。
shape:碰撞形狀的形狀索引。
如果射線沒有發生相交,則返回的是空字典。
bool intersect_ray_into(parameters: PhysicsRayQueryParameters3D, result: PhysicsIntersectRayResult3D) 🔗
Intersects a ray in a given space. Ray position and other parameters are defined through PhysicsRayQueryParameters3D.
If the ray hits a shape, this method returns true and writes the intersection information into the PhysicsIntersectRayResult3D object passed in result. If nothing is hit, it returns false.
Array[Dictionary] intersect_shape(parameters: PhysicsShapeQueryParameters3D, max_results: int = 32) 🔗
檢查通過 PhysicsShapeQueryParameters3D 物件給出的形狀與空間的交點。相交的形狀在包含具有以下欄位的字典的陣列中返回:
collider:碰撞對象。
collider_id:碰撞對象的 ID。
rid:相交對象的 RID。
shape:碰撞形狀的形狀索引。
可以使用 max_results 參數限制相交的數量,以減少處理時間。
注意:該方法不考慮物件的 motion 屬性。
bool intersect_shape_into(parameters: PhysicsShapeQueryParameters3D, result: PhysicsIntersectShapeResult3D) 🔗
Checks the intersections of a shape, given through a PhysicsShapeQueryParameters3D object, against the space.
If one or more shapes are found to intersect, this method returns true and writes the intersection data into the PhysicsIntersectShapeResult3D object passed in result. If no shapes are found to intersect, it returns false.
The number of intersections can be limited using PhysicsIntersectShapeResult3D.max_intersections, to reduce the processing time.
Note: This method does not take into account the motion property of the object.