Creating and Using QAreaBodyNode - erayzesen/godot-quarkphysics GitHub Wiki
Unlike other physics objects, QAreaBodyNode objects do not engage in physical interactions with other objects in collisions. Instead, they serve as areas in the scene that detect when other objects enter or exit their boundaries (via collision_enter
and collision_exit
signals).
Additionally, QAreaBodyNode objects can remove gravity from dynamic objects within them (gravity_free
) or apply a specific force to those objects (linear_force_to_apply
).
How to Create a QAreaBodyNode Object?
You can create a QAreaBodyNode object by adding it to the scene tree just like any other node. If you add child nodes such as QMeshRectNode, QMeshPolygonNode, QMeshCircleNode, or custom-designed QMeshAdvancedNode under it, your QAreaBodyNode will be ready to work in the basic sense. You can also make the necessary adjustments via the Inspector. Additionally, it is possible to add it via code.
var my_area_body=QAreaBodyNode.new()
my_area_body.global_position=Vector2(500,500)
add_child(my_area_body)
var my_mesh=QMeshRectNode.new()
my_mesh.rectangle_size=Vector2(128,128)
my_area_body.add_child(my_mesh)
How to Use collision_enter and collision_exit Signals?
When a QBodyNode object first collides with a QAreaBodyNode, the collision_enter signal is triggered. When it exits the collision, the collision_exit signal is triggered.
Below is an example of a QAreaBodyNode script that increases body_count value by 1 when collision_enter occurs and decrease body_count value by 1 when collision_exit occurs.
extends QAreaBodyNode
var body_count:int=0
func _ready() -> void:
#Connecting on_collision_enter signal
connect("collision_enter",on_collision_enter)
#Connecting on_collision_exit signal
connect("collision_exit",on_collision_exit)
func on_collision_enter(area_body_node,collided_body_node) :
#Checking whether the collided body is QPlatformerBodyNode
if collided_body_node is QPlatformerBodyNode :
#Increase the body count
body_count+=1
func on_collision_exit(area_body_node,collided_body_node) :
#Checking whether the collided body is QPlatformerBodyNode
if collided_body_node is QPlatformerBodyNode :
#Decrease the body count
body_count-=1
QAreaBodyNode Properties in the Inspector
- Gravity Free -
gravity_free
: Disables gravity for all dynamic objects that remain in collision with the QAreaBodyNode. This is disabled by default. - Linear Force to Apply -
linear_force_to_apply
: Applies a specified force to all dynamic objects that remain in collision with the QAreaBodyNode every frame. The default value is Vector2(0,0).
To learn more about all the methods and properties of QAreaBodyNode, refer to the QAreaBodyNode page.