Phobos-developers / Phobos

Ares-compatible C&C Red Alert 2: Yuri's Revenge engine extension
GNU Lesser General Public License v3.0
268 stars 83 forks source link

Fix ballistic weapons overshooting when height difference is present #24

Open MortonPL opened 3 years ago

MortonPL commented 3 years ago

As of now, units with INI key Lobber=yes "overshoot" their targets (projectiles land behind targets) if said targets are on higher elevetion. I propose to introduce a flag (i.e. IsAccurateLobber=true|false) that would disable/enable this penalty.

Metadorius commented 3 years ago

@MortonPL this is not a feature, this is a bug. I actually gathered some info on this quite a while ago, lemme repost it here. It's a letter from LH_Mouse.

在 2019/8/21 3:56, Kerbiter 写道:

Hello!

I'm a small modder C&C modder helping the modding community on PPM and discord here and there. I'm trying to help investigate the ballistic projectile arking issue when projectiles land on an elevation different from the firing point. Some time ago one of the modders said that you could help identifying the issue. Do you have any knowledge on the issue? It is really frustrating to have a weapon that misses most of the time and can't be fixed. I would really appreciate any info, be it gamemd.exe addresses or anything else. In case you can't help - it's OK, anyways. Thanks for your attention

Cheers, Kerbiter

It's because the ballistic of an arcing projectile is calculated using the global Gravity= and the start and end coords. As the gravity is constant, if the initial angle is fixed, the speed of the projectile in question is proportional to the distance, which also answers why Speed= on weapons using arcing projectiles has no effect.

From middle school we have learned that the initial angle can be computed by solving a quadratic equation. Usually this will result in two roots, the larger of which is picked when Lobber= is yes and the other is picked otherwise. This is how YR works.

Now let me talk about your original question: Why do shells fail to hit their targets if they are higher than the firers? It is because, if the elevation difference is large enough, there might be no solution to the aforementioned quadratic. The engine hard-codes the initial angle to 45 degrees in this case. Apparently if you would like to fix this issue you just need to increase the initial speed, to make the quadratic never unsolvable. That's it.

-- Best regards, LH_Mouse

secsome commented 3 years ago

Let d = XYdistance, h=Zdistance, v0=speed, g=gravity, then the function in 48A9D0 is just solving the angle.