So, say I have a mortar model with a movable tube that goes up and down and a base that rotates it left and right. I have been trying to find an equation for the firing of a projectile that start inside the mortar tube. However, I need it so that the target distance has no maximum (it can fire at any range). The equations I have found thus far either were not applicable or were poorly explained. Not really a math guy, so I was hoping someone could give me some information on how I can achieve this via blueprints. Any help would be appreciated.
What exactly are you trying to determine:
(1) what angle/launch velocity the mortar needs to be at for a projectile fired from it to hit a specified target location? Or
(2) where a projectile will land (and/or its airborne trajectory) given a specified angle and launch velocity?
The latter is substantially more complicated but I’ve done something really similar for my game and I can share my approach.
I know where it will land. The target point will be where the user clicks. So, I am trying to figure out #1
I do not know how RythmScript has time to make a game as he is always helping people on the forum…Curse you RythmScript, get back to work I wish to see your awesome game…J/k
It sounds to me like you’re looking for Suggest Projectile Velocity…Set whatever Range you want for the End location via Variable or something…then use the Toss Velocity you find into Launch Actor/Character…
BUT…I’m very willing to bet RythmScript has a much more awesome way of doing this (as he’s helped me many a time) so that may get you started but hopefully he’ll be back to help more…
It largely depends on were you want to simulate air drag affecting trajectory of grenade or not. If you don’t care about air drag then, as President said, Suggest Projectile Velocity node should work for you.
Physics simulation is kind of unstable, maybe not even that, but its easy to do mistakes and get nice looking but not correct results from it.
My point is that while there are very accurate formulas for ballistics, physics in unreal is not always accurate (for eg. low/hig fps changes results).
So imo only one accurate solution is to trace this in real time.
Theoretically if you increase speed 10 times and increase force pushing down you should get quite accurate results 10 times faster.
And those results need to be updated only if player changes elevation so you could trace just 2 curves one below one above current elevation and store results in array.
There is even more optimizations you can do, you do not need to trace them every 1/10th of deg, you could do it like every 5 deg or so, this all depends on distance and accuracy you want get.
Or you could just trace such curve every 1deg and store all results in array
Then play those results for shooting instead of physics.
This way you always get accurate and consistent results.
I was going to recommend Suggest Projectile Velocity as well… If all you need to know is what vector to launch a projectile at to hit a specified destination, it’s really just simple math, and the SPV node wraps that math up in a nice little package.
Where this can get tricky is how “smart” you want the mortar to be. For example, do you want it to attempt to adjust this velocity to a lower-angle-higher-force alternative if the original trajectory is blocked by something (like a cliff face or building)? That starts to get more complicated, because then you have to trace across the trajectory looking for blocking hits before actually firing, and may have to recalculate…
Awesome, the SPV node works pretty well. I may need to modify it later but it should suffice for the time being. Thanks.
Maybe this will help if you need to modify the code or want to write it yourself. SPV is all well and good, but if you want the projectile to have a pre-set initial velocity (more realistic) you’ll probably want to code in the angle calculation yourself, there’d be a few factors to consider.
In Gears of War they used a different system again, you determined the hit location while “charging” the weapon, and it would launch the projectile. If I recall correctly and in the interests of gameplay; rounds would always hit the ground at the same time regardless of the difference in distance. Unrealistic, but good for game-play. SPV won’t help you with that though.
You could plot the trajectory based on the equation and then have the projectile follow the points along it, kinda like an invisible spline, if you wanted to do the above.
I have found this site to be very helpful for this topic : Trajectories