There are many ways to do this.
If you want more information about the physics events on a RigidBody, you'll want to implement the _integrate_forces(state):
function. The state object contains many things you can query from.
The setup in your case you can use it fine without actually creating your own integration, you can just have it do queries. But if you want to do custom integration as well, you have to make sure you check the custom integration option on the properties, or set it in script.
Outside of that you want to make sure your RigidBody has at least 1 reported contact, their default is 0.
Then a simple example might look like:
func _ready():
set_max_contacts_reported(1)
func _integrate_forces(state):
if(state.get_contact_count() > 0):
print(state.get_contact_local_pos(0))
If you want to see what else is on hand for the state, I'd refer you to the docs here: http://docs.godotengine.org/en/stable/classes/class_physics2ddirectbodystate.html#class-physics2ddirectbodystate
Another alternative is to use a raycast that has it's direction continually aligned to the ball's heading. You should be able to extract collision details from it.
If you're determined to use _fixed_process(delta)
, there are no methods that give you easy queries to the physics state. You can make calls to the Physics2DServer and do special queries, like ray casts and shape intersections.
Outside of that, inside the processing loop you can detect the collision, but you're on your own as to calculating the collision point. A simple method might getting the collision object from the array returned by get_colliding_bodies()
, then doing a line intersect test on the heading of the ball (to some length beyond it's radius) against the line draw from the top and bottom points of that bat's contacting edge. Since it's a straight rectangle and circle, the point of intersection is probably roughly accurate.