I’m trying to create a beginner project - a soccer free-kick game. The ball is defined as an Actor with a physics-enabled static mesh (BP_Ball).
How can I configure my Player to apply a force to the ball when I hit spacebar? The Enhanced Input is already working (the game displays ‘kick’ when I hit the spacebar), but I can’t figure out how to get BP_Ball and apply a force to make it move.
I also wanned to share my approach that I’ve been preparing meanwhile so it doesn’t go to waste, even tho the blueprint code above would work perfectly fine.
What I came up with allows us to interact with multiple balls while requiring the player character to get close enough to be able to kick.
Here’s how to set it up:
Inside your ball actor’s BP, navigate to the Components window on the top left and there, add a static mesh component (which you already have I suppose but also make sure to have it as the root by dragging it over the default scene root) and a collision volume as its child like this:
Then while having your static mesh component selected, navigate to the Details window on the right side, and under the Collision section, set the collision preset to custom and set the Pawn class to be ignored like this:
This way when the Simulate Physics property is enabled, our player character won’t be able to interact with the ball by walking over it since we want an input to be required for it.
Now inside our player character’s BP, implement this blueprint code into the Event Graph: