|
|
|
|
Reply From: |
eons |
body_enter
signal will tell you about each collision when they happen (you need contact monitor).
get_colliding_bodies
gives you an array with the bodies colliding IF contact monitor is true (default false), the size of the array will be as large as the collision max count (default 0).
Kinematic bodies works different, these have a simple collision detection that works only when (after) using move
or move_to
during _fixed_process
Kinematic character and platformer demo have many examples.
I suppose I can look into even more demos. I am aware of the functions. I just need to put it all together. Mainly for the scope of this question, I need to detect whether or not it is a “Player” node or a “Floor” node on the script attached to the moving object.
jjphung | 2017-04-08 07:31
Once you have the collider (with rigid signal or kinematic function) or the array with colliders (rigid function) you can check in many ways.
I prefer to use groups (is_in_group
) because is flexible.
If you have a good collision layer design, these can be used to distinguish the type of object too.
The node name or part of the name can be used too, also node class/parent class.
The best way may depend on your design.
I finally got the Player node and have access to it. However the get_colliding_bodies
always turn up empty:
var bodies = get_colliding_bodies()
for body in bodies:
if body.is_in_group("Player"):
print("Game Over")
The tree structure is below. The Meteor node is instantiated as get_tree().get_root().add_child(newMeteor)
at run time. Here is the Tree Structure.
jjphung | 2017-04-09 05:13
Solved it! Had to set set_max_contacts_reported()
since it defaults at 0, explains why get_colliding_bodies
array turned up empty! Then I used:
var bodies = get_colliding_bodies()
if player in get_colliding_bodies():
print("Game Over")
jjphung | 2017-04-09 06:36