0 votes

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.

in Engine by (12 points)

1 Answer

0 votes

can you post post the part of code about physics2dtestmotionresult

by (102 points)

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.

Categories