0

So I want to have my projectiles travel to a targeted position with in a certain amount of time and have a curve trajectory with a max height. I have watchh a couple youtube tutorials but they're just simply not want I need right now is there a way for me to do this ?

I followed this tutorial as first but I can't increase the speed and reduce the time and the height to my liking: https://www.youtube.com/watch?v=Qxs3GrhcZI8

Thien
  • 101
  • 1
  • 10
  • 1
    If you don't have other factors, like wind resistance or alike, you can just use the basic formulas from your physics class. The initial energy of the projectile (`1/2*m*v0_y^2` projected upwards is converted to potential energy at the highest point of the trajectory (`m*g*h`). A bit more 11th grade math and you will get there. – BitTickler Aug 05 '22 at 06:39
  • why not use real physics instead see [Projectile Aim Prediction with Target Acceleration and Bullet Deceleration Varying with Angle](https://stackoverflow.com/a/71817221/2521214) – Spektre Aug 05 '22 at 13:31

2 Answers2

1

You have a targeted position implies that the distance between the user and the target is r (say). Now, you want the projectile to hit the target in a certain time t. Let's say the projectile was thrown at a velocity v. Below are the calculations that yield the result of how much velocity and angle of projection are required to achieve the hit in the given time t

enter image description here

The question says

have a curve trajectory with a max height.

Theoretically, the maximum height is achieved when the angle of projection is 90 degrees with respect to the ground and the cosine of 90 is 0. Substituting the value of cos(theta) in the resultant equation results in the value of velocity being infinity, which is practically impossible.

Hence, with the given range and time of flight, two variables, the velocity, and angle of projection can be configured. If the maximum height that you want to achieve is specified, the angle of projection is calculated accordingly.

Geeky Quentin
  • 2,469
  • 2
  • 7
  • 28
  • Apologies for uploading a handwritten text, I haven't quite learnt writing in latex yet – Geeky Quentin Aug 05 '22 at 06:54
  • No problem I actually prefer handwrriten – Thien Aug 05 '22 at 06:56
  • @Thien, does my answer not help you? Mention if it worked or not, if it didn’t, please provide more details and i will edit my answer – Geeky Quentin Aug 05 '22 at 15:34
  • It only help me a bit but it's not the solution I'm looking for and I already figured out a solution to this which only apply to the current game I made and it's pretty much a very hacky method so I won't post it here – Thien Aug 08 '22 at 02:03
1

Unity Slerp will be a good fit for you. You can specify the start, end point and also control the time. You won't be able to control the height as its dependent on the Vectors.

Here is the Link to Unity Docs https://docs.unity3d.com/ScriptReference/Vector3.Slerp.html

Vionix
  • 570
  • 3
  • 8