How to hit an object?

Godot Version

4.2.2

Question

Basically, I want to have the player strike in front of them when a button is pressed, and if there is an object with the group “ball”, then to have that object move in a direction up and away from the player.

I have created an Area2D with a Collision2d attached to the character in front of the player (technically the sprite, since the sprite can turn around with the player) and set it so that when the “attack” button is pressed, the collision body with become active.

I have a ball with a “hurtbox” area with a collision body that is in the ball group.

I am not sure where to go from here. Are there any good resources that explain how to use scripts to change the movement of objects, and how to use detection to see if an object is in an area? I’m having a really hard time finding any relevant materials for Godot, aside from paid courses that teach you make a very specific game… I’d rather not pay $200 for a course that I’m not sure will even be relevant, and will definitely have a ton of irrelevant information.

EDIT: If you read this, then thank you! However, I seem to have fixed this issue and am now on to the next one. If you are stuck on this same problem, what was happening for me was I was assuming that the signal “on_area_entered” would not work if the node was created within the area. It turns out it does! So if you need something to detect if another area is within it, feel free to use the signal that checks for entering!

For a rigidbody you can use apply_central_impulse to simulate a simple physics based hit

Wait, that’s amazing! I’ll try that out, thank you!