In short: just read the title.

What I have tried: I have a ball implemented as an Area2D because a KinematicBody2D can be stucked in some corner case, that happen frequently in my game. But I also need the collision normal. In another topic the complicated function "collides_end_get_contacts" works in some configuration but can easily brings segfault which is unacceptable. As instance, if a CollisionShape is not at pos 0 0. (thank you Godot local coordinates hell..) the returned array of points is empty despite the fact the collision happens. Of course I can make sure all Collision Shape are in 0, 0 but you can understand it is not the safest solution.

I search for something more safe to get the collision normal of every shape that enters my Area2D. The PhysicsServer is about 3D. I don't even know where is the 2D equivalent. I tried to find where KinematicBody2D gets collsion normal. But i'm lost in the source.

https://github.com/godotengine/godot/blob/3.2/scene/2d/physics_body_2d.cpp (where the hell the variable "normal" of KinematicCollision object is updated ?? )

Anyone can points me in the right direction ?

I'm not sure if it would help, but two thoughts on how you could get a collision normal:

One: Use a KinematicBody with the layers/masks disabled so it can respond to the physics world but not react to it. Then you can use something like move_and_collide with the testing boolean on to get the normal by "moving" the KinematicBody before moving the Area. It might be a bit of a mess to get setup, but that might be one way to get the best of both worlds in one go.

Two: Use raycasts to get an approximation of the normal. You could raycast from the global origin of the object to the global origin of whatever object just entered, which would not perfect would potentially give an idea of the normal of the node that just entered.

I dropped the Area2D idea. I set a RigidBody on "character" mode, gravity direction to 0, 0, reported contacts to 1. I get the collision normal in the Physics2DDirectBodyState.

var bodyState:Physics2DDirectBodyState

# The signal "body_entered" is connected to this function.
func _on_Ball_body_entered(body):
	# I guess the contact array always contains a value at index 0, because a body has entered,
	# maybe a null check before this call would be safer.
	collNorm = BodyState.get_contact_local_normal(0)

func _integrate_forces(state):
	bodyState = state

The ball behaves like I want now. I'm not sure to get the full control of translations as I searched with the Area2D, so it needs some experiment. At least, the question in the title is answered.

You can also use PhysicsDirectState (or the 2d variant) it has calls to move a collision shape and collect a collision. There are other calls to collect contact points a body is colliding with.

2 years later