How can i detect a collision from a CollisionPollygon2D in a object?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Johnz
:warning: Old Version Published before Godot 3 was released.

For collisions detection usually body_enter signals can be used, but can you elaborate little more about what you trying to do?

Freeman | 2016-02-22 23:48

Enjoy New Arrival BTS Merhcandise T Shirt, Limited Stock. All Colors are Available in our BTS Merch store. Come Fast and Order Now[.][comment1-1]

bts t shirt | 2022-11-15 10:28

:bust_in_silhouette: Reply From: Ryan Brent Taylor

I’d recommend going through the physics tutorial here.

This depends a lot on what you’re trying to do. There are three main physics body types in Godot: KinematicBody, RigidBody and StaticBody. These are implemented as nodes. Further, they need a Collision object as a direct child node to define the shape of the physics bodies (CollisionPollygon2D in your case).

Now, collision reporting can be very expensive so generally speaking, RigidBody and StaticBody physics controllers do not report collisions. You can change this by increasing the number of contacts reported in the properties of your StaticBody or RigidBody node.

You can find a handy chart indicating who has access to what information in a collision here.

Here’s the documentation for RigidBody2D, KinematicBody2D and StaticBody2D.

The more important functions/methods you’re going to use for getting collision information reported to KinematicBody2D are as follows:

The more important functions/methods you’re going to use for getting collision information reported to RigidBody2D are as follows:

As for getting information reported to StaticBody2D, here’s a rule of thumb: Don’t.

I am currently trying to detect collision in a RigidBody2D , but it is divided into two parts, the bottom and the top , I need to detect which of these parts occurred the collision. I already detected a collision using the body_enter signal , but it seems that does not help me with the condition cited above

Johnz | 2016-02-27 19:16

Hi!
Thanks for your answer.
It seems that the link you provide here is not available anymore:

You can find a handy chart indicating who has access to what information in a collision here.

At least I did not see it on DDG in the free search.

dimonade | 2022-07-24 21:51

:bust_in_silhouette: Reply From: tygris

I’m late to this thread but i wanted to show this loop I use to detect if a collision happened and then execute orders based on the result.

for i in get_slide_count():
	var collision = get_slide_collision(i)
	if i>0:
		#Do your action here

get_slide_collision Should be called after move_and_slide(),it returns an Integer and will return “0” if no collision occurred.

Hope this helps someone!

Hi. I’ve tried but not work. Can you help me?

My code:

func _physics_process(delta):
for i in get_slide_count():
var collision = get_slide_collision(i)
print(collision.collider.name.begins_with(“PLAYER”))

Thanks…

tncft4 | 2021-01-17 15:39