Obtain colission point between RigidBody2d and other 2d Physics Objects

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By KenjiGlove

Hey everyone,

I’ve got a ball, which bounces around like in a game of snooker. It detects colissions via the following signal:

func _on_Ball_body_entered(_body):
  print ("Boing~!")

Besides printing "Boing~!, I’d also like to know the exact position of the collission. I want to know this because I want to play an explosion animation at the collision point whenever the ball bounces against something.

It seems simple, but I’ve been searching around the web for a while without result, The closest I got was this:

func _on_Ball_body_entered(_body):
    print ("Boing~!")
    print ("CurrentPosition", get_position())
var p =Physics2DTestMotionResult.new()
test_motion(get_position(), true, 1, p)
var ColissionPoint = p.get_collision_point()
print ("ColissionPoint =", ColissionPoint)

Which gives bugged results depending on the angle of the collision. It works fine if you bounce against something on the right:

enter image description here

But whenever you bounce against something to the left, it thinks you’ve bounced against something unrelated on the right instead.

There has to be an easier and accurate way to get a colission position at any rate.

Please help me out bros!

Thanks in advance.

:bust_in_silhouette: Reply From: mohamedLT

can you post post the part of code about physics2dtestmotionresult

The code I showed is everything I have regarding physics2dtestmotionresult. Is there something that’s missing?

Do note that the whole physics2dtestmotionresult is just a bad attempt that I made. If there’s a better way to obtain the colission point without it, I’d use that instead.

Thanks for trying to help

KenjiGlove | 2020-08-15 07:11