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...
RayCast2D¶
Inherits: Node2D < CanvasItem < Node < Object
2D 空间中的射线,用于查找第一个相交的 CollisionObject2D。
Description¶
Raycast 代表的是从它的原点到 target_position 的射线,如果与碰撞对象相交,就能找到路径上距离最近的 CollisionObject2D。可以用来做很多事情,例如
要让 RayCast2D 忽略某些对象,可以将它们加入例外列表,也可以让检测汇报忽略 Area2D(collide_with_areas)或 PhysicsBody2D(collide_with_bodies),还可以配置物理层。
RayCast2D 每一个物理帧都会计算是否相交,计算结果会保留到下一个物理帧。如果要立即执行射线投射,或者你想要在同一个物理帧内多次配置 RayCast2D,请使用 force_raycast_update。
要扫描 2D 空间中的某个区域,可以使用多个 RayCast2D 去近似,也可以使用 ShapeCast2D。
Tutorials¶
Properties¶
|
||
|
||
|
||
|
||
|
||
|
||
|
Methods¶
void |
add_exception ( CollisionObject2D node ) |
void |
add_exception_rid ( RID rid ) |
void |
clear_exceptions ( ) |
void |
|
get_collider ( ) const |
|
get_collider_rid ( ) const |
|
get_collider_shape ( ) const |
|
get_collision_mask_value ( int layer_number ) const |
|
get_collision_normal ( ) const |
|
get_collision_point ( ) const |
|
is_colliding ( ) const |
|
void |
remove_exception ( CollisionObject2D node ) |
void |
remove_exception_rid ( RID rid ) |
void |
set_collision_mask_value ( int layer_number, bool value ) |
Property Descriptions¶
bool collide_with_areas = false
If true
, collisions with Area2Ds will be reported.
bool collide_with_bodies = true
If true
, collisions with PhysicsBody2Ds will be reported.
int collision_mask = 1
光线的碰撞遮罩。只有在遮罩中启用至少一个碰撞层中物体,才会被检测到。有关更多信息,请参阅文档中的 《碰撞层与掩码》。
bool enabled = true
如果为 true
,将报告碰撞。
bool exclude_parent = true
如果为 true
,父节点将被排除在碰撞检测之外。
bool hit_from_inside = false
如果为 true
,射线会在从形状内部开始时检测到命中。在此情况下,碰撞法线将为 Vector2(0, 0)
。不会影响凹多边形形状。
Vector2 target_position = Vector2(0, 50)
光线的目标点,相对于该 RayCast 的 position
。
Method Descriptions¶
void add_exception ( CollisionObject2D node )