Download

Grenade Throwing and how to correct the throw direction?

Ok guys, I’ve got a grenade throw working. I spawn the grenade in my hand on press, and on release I launch the grenade, set it to a physics object, and set off the explosion effects and sounds at the hit location. The projectile prediction for the arc looks ok. I still need to create a beam emitter or attached something and use the data from the arc but I can do that later. For now the debug arc is fine. My problem has crept up when I actually added the throw animation to the flow of everything. The prediction of the throw from the idle throw stance looks accurate but as the grenade leaves the hand it is flying off in the wrong direction. The only thing I can think of is that when I grab the socket location and add my velocity adjustment to create the impulse the socket has rotated during the animation making the direction all wrong. Any ideas on the math to fix this? I’ve also tried rotating the socket to get the x direction pointing forward at the release point in the animation but I haven’t gotten that to work yet either. Any ideas what could be wrong or how to fix?

So to recap during the idle aim animation state the prediction of the projectile looks accurate.
Now When I throw the grenade it isn’t traveling forward and is now traveling off in odd directions.
Ohh and I can confirm collision isn’t the issue. Ignore pawn is on.

I think I figured it out. I need to figure out a fix. my projectile prediction isn’t updating after press. The launch is using the the initial press location and not the updated camera rotation. <— there is the answer i think.

Ok none of my fixes seems to be working. So I created a couple videos on my phone and uploaded them to Facebook. Here are the links. Please check them out and let me know if you guys see anything that could be improved. I already thought of one improvement that could be made is that after the timeline for the damage radius elapses I should start the grenade explosion and do damage for holding the projectile to long, or another solution could be to auto fire the grenade at that point. I think that second option is how Anthem currently does it. There are two videos the shorter video shows the functionality I had prior to adding the animations. The 2nd video I go through the blueprint of the grenade setup and show where I am adding the impulse to the mesh of the grenade. Thanks for any help in advance.

You should post your blueprint setup to https://blueprintue.com so people can actually scroll around and look at things appropriately instead of through a video with you pointing out the nodes step by step. Hard to get a full understanding of the nodes and how they relate. As for the actual issue, pretty sure it is because you attach the grenade to a socket, then animate that socket and you mess up your rotations because the animation does not follow the nice and clean “predicted path”. If you will notice from the attached pics the prediction start location of the socket and the actual release point are very far apart. How can you expect it to make an accurate prediction from those values? Probably going to take some tinkering but I would try and pin down the exact transform of the throw at the point of release relative to the idle position. You will either need to trace from the animation release point for an accurate “arc” and fake the visual to display from the idle position to the target end location or do a bunch of math and calculate the velocity and rotation necessary to reach the end point determined from the idle pose when starting from the rotation and location of the release point.

Thanks for heads up. The math is def where I am needing an adjustment. I’ve gotten closer but not perfect yet. I’ll post some pics of the BP.

Cool, just a question since I don’t deal with animations…is there a way to get the transform of the socket in the final pose just before release? If you can that would simplify this a lot. Then it will be figuring out the math to go from that transform to the initial transform…(mainly the rotation, this will at least get it going in the correct direction). My theory is that if you start with a rotation of 0 degrees but at the release point of the animation the socket is at 45 degrees (just an arbitrary value), then you would correct the trajectory by rotating the velocity vector by -45 degrees to get it to point in the direction of the initially predicted path. This may result in a projectile that takes the appropriate directional path but lands further than expected due to the difference in height between the idle and final pose of the socket. You could then decrease the magnitude of the velocity to account for this difference. The final thing would be adjusting if the socket has translated along the horizontal plane at all, this would then need to be corrected similarly to the rotation issue.

I have searched for this very thing Nebula, but I have not found anything other than the socket transform, socket rotation, socket rotation nodes. I have not yet figured out how to grab the socket transform at a specific point in time. I noticed in Anthem there is a disconnect between the launch of the grenade and the animation. It almost appears the solution in Anthem was to speed up the animation. In Fortnite I think they do two things. They spawn the grenade in the hand, but do the projectile prediction from the front of the head. They then spawn the grenade from the front of the face to launch and destroy the one in the hand. Def need some help here. I have not yet set on a solution.

Maybe try playing around with a spawn point to see if you can find the location relative to the idle position where the hand would actually release the grenade. So say, idle position is (0,0,0) and the hand release point is (25,15,150) relative to the idle position…just as an example, try and find the location by trial and error of where spawning a grenade would appear to come from the hand at the release point. Then you could determine the amount of time it takes for the hand to reach that point once the player has decided to throw the grenade. Spawn in a new grenade at that location after a delay of “X” amount of seconds, and destroy the idle one. Then once we get that figured out we can begin to figure out how to get the grenade to travel from the release spawn point to the idle position target.

Hey.

You might want to look at the SuggestProjectileVelocity Custom Arc node.

UE4Editor_XhLR1BH62y.png

It takes in a starting point and an end point and gives your object the exact velocity needed to travel between those two points.

Using this node and based on the logic I believe you have, you can set the End Pos while you are doing your aiming (the point where your aiming arc hits)
Then the moment you want to release your grenade, you can set its location as the Start Pos.

This should solve your problem with the minimum amount of redoing logic.

Hope it helps. :slight_smile:

  • Dan

Thanks guys! I think I got some more things to try today. I’ll let you know how the progress is going.

You are a life saver Dan!!! Totally got everything working using that node you provided. Matching up the animation to the release is still a trick. Currently using delays to adjust the timing. Any other tips to get the launch of the impulse to match up with the animation?

Dude, I thought you WERE using that node this whole time haha There is one that predicts the projectile path and another that predicts velocity. But yes, you still need to figure out the true release point…so I am glad I didn’t send you down a rabbit hole for days searching for things you weren’t even using from the engine! oops…should have clarified. Isn’t there a way to check the animation duration and key framed positions in like MAYA or wherever you animated and see how long before the arm is at the location of release?

I have gone into the anim editor and previewed my throw anim. I scrub the timeline to the release point where the anim notify for release is and see an elapsed time of .828 sec. Going through my logic I thought a delay of this exact number would work but its still off imo. I use the predict projectile path nodes. I just hadn’t noticed the suggest node. The animation matching up better is pretty nit picky imo. My concern now is the speed of the grenade leaving seems slow compared to the actually force displayed in the throw anim. I’m thinking I should just add some speed in the x direction and speed it up. Haven’t tried this yet. Any ideas?

haha, you asked for suggestions I am just making suggestions…I don’t know what the iterations look like. If you think perfecting the animation is nit picky that’s fine. Like I said, I just go off what you tell me. So if the animation lines up well enough with the spawn and release of the grenade then cool. As for the other thing, I am not sure how you would add “speed” to it without changing the final location since the trajectory is dependent on the release velocity. Do you have a video of what it looks like now??

I’ll record a video and get it uploaded. Thanks so much for all the help!

Actually, now that I think about it, maybe we are approaching this from the wrong angle. What if we started with the release point trajectory, put in a velocity that “looks good” and calculated where it would land using the “predict projectile path” node. Once we have the “end” location we then extrapolate back to the idle position and trace from idle to calculated end. I think that makes more sense than starting at the idle position to generate the “end” because that is a static pose and doesn’t give you room to manipulate things. If the animation and the release velocity look good it will be easier to just line that up with an “idle” trajectory than the other way around. Just a thought…

You can try tweaking the Arc Param variable in the SuggestProjectileVelocity node. That adjusts the angle of your arc, which can make your projectile appear faster/slower.

Thanks dan I will give it a go today. Another great Idea Nebula. Looking at this backwards could def be helpful. I’ll look into that as well.

Ok guys adjusting the arc seems to be the solution I’m going to go with for now. The next problem I have is when throwing short vs long the animation is the same. I have an animation for a long throw and a short throw. I just need to setup the short throw in the anim blueprint just as i did the long throw. The question is what are the different ways I could try to determine if I want to be in short throw or long throw. I’m thinking something like this…

use the projectile prediction to get the start and end point
break the end point vector into x,y,z
Look at the value of X and if its greater than say 500
Set the far throw bool to true and continue to throw like I’ve got it
If that is false set the throw short bool to true and transition into the throw short animation.

Would something like this work? Am I on the track? Any suggestions?