Shooting an object directly at specific target (Hockey puck)

Hi all,

I’m fairly new with coding and blueprints so hopefully this will be an easy answer for yall.
I’m trying to create a hockey game and I want to be able to have a tracer and target show up for where you’re aiming (trajectory I suppose).

What I’m trying to accomplish is

-Player holds shoot button then tracer, beam and target become visible and controllable.
-Upon release of the shoot button the puck will launch towards the target

How I’ve set it up so far (for debug purposes)

-BP belonging to the Puck mesh has a custom event called SlapShot
-Slap shot GETS location of a noCollide mesh in my Player blueprint
(Location where the puck should be possessed)
-BP belonging to the Puck mesh then sends a float back to the SlapShot event that dictates how many times the result of the location should be multiplied
-I call for SlapShot in my Player BP as well as spawning the puck mesh.
-Depending on the location of the Target mesh and beam it sends the location back to
my SlapShot event with the result.

I’ve been using AddImpulse and AddForce as well as some other node I can’t recall.
and although the puck DOES launch it is ALWAYS offset. I’ve tried different meshes, static and skeletal, played with the simulate physics.

I’ve tried adding and subtracting from the Y axis to create an offset however when I move my character it continues launching almost directly forward (wherever my player model is facing) instead of towards the target.

I could be missing something super obvious and I’m really hoping someone can point me in the right direction :frowning:

Character BP :

Biscuit BP (Puck) :

While trying to debug the situation I attached an arrow pointing forward on the puck mesh and everytime it spawned in it was EXACTLY where it needed to be facing, so I imagine it has something to do with my “launch” system that is the problem…

And for the time being I removed my “power up shot” timeline to try an expose the directional issues.

Ultimately I would like there to be a float that dictates how fast the puck should move but for the time being I would like it to stop glitching out after moving my player.

Example Video :

Any guidance would be greatly appreciated <3

hi,
i have here a little example… this is a basket ball but the principles should be the same…

here is what it does

and here the quick steps :slight_smile:

this is on your character that shoots the puck / basketball / ?
you can improve on it and add for example more ThrowSpeed when holding down the button or add a higher or lower arc when interacting with the mouse wheel… in which case i was to lazy, i am sorry :stuck_out_tongue:




this is my simple basket ball…



here we draw the debug trajectory and set it´s points…



as you can see there is a lot you can make much better but i hope this can get you on the right way :slight_smile:

cheers :vulcan_salute:

Dude, you are an absolute SAINT. Thank you SO much for all the in depth answers!
I’m going to try to rebuild my puck system more like what you’ve shown me, I will post the outcome when I get it all together :slight_smile:

again, thank you so much dude!

hi,
no problem, hope it helps you :slight_smile: looking forward to see your puck fly :+1:

cheers :vulcan_salute:

I know I’m late to responding to this but I was able to use portions of your blueprint to fix my problem :slight_smile:

Thanks again!

hi,
no problem, i am glad it helped you :slight_smile:

cheers :vulcan_salute:

for the hold to aim flow you want two pieces: a preview while held and a solved launch on release. while held, run PredictProjectilePath from the puck toward the aim point each frame and draw it as a spline or debug line so the player sees the arc. on release, use SuggestProjectileVelocity to get the launch velocity that lands on the target and apply it to the puck.

for charge power just scale the launch speed with hold time and redraw the preview with the same speed, so the shown arc is always the arc the puck will fly. if the solver returns no solution the target is out of range, which is a nice time to tint the target red.

you can also try Gravity and Ballistics Toolkit, a trajectory and launch toolkit for Unreal Engine that predicts arcs under the real field and solves low arc, high arc or fixed time launches to a target: Gravity & Ballistics Toolkit — Planet Gravity, Zero-G & Arc Prediction | Fab