struct
Godot::PhysicsHit2D
- Godot::PhysicsHit2D
- Struct
- Value
- Object
Overview
Strongly-typed 2D physics intersection hit result.
Encapsulates collision location, surface normal, and hit object reference with built-in dead-pointer protection.
Usage Example:
if hit = raycast_to(target_pos)
# Standard Crystal downcasting with dead-pointer safety:
if enemy = hit.collider.as?(Enemy)
enemy.take_damage(25)
end
end
Defined in:
libgodot/extensions/physics.crConstructors
Instance Method Summary
-
#collider : Godot::Object | Nil
Returns the hit collider if alive, or
nilif already freed or absent. -
#normal : Vector2
The surface normal vector at the intersection point
-
#point : Vector2
The global intersection coordinate
-
#rid : RID
The RID of the colliding physics body or shape
-
#shape : Int32
The shape index within the colliding body
Instance methods inherited from class Object
try?(&)try? try?
Constructor Detail
Instance Method Detail
Returns the hit collider if alive, or nil if already freed or absent.
Rationale & Dead-Pointer Protection:
If the collider node was destroyed by Godot or GDScript (e.g. via queue_free())
during the current physics step, accessing a stale pointer causes a segmentation
fault (0xC0000005).
#collider dynamically validates #alive? before returning, safely yielding nil
if the native instance was deallocated.
Pair with .as?(Type) for idiomatic, type-safe downcasting:
if player = hit.collider.as?(Player)
player.heal(10)
end