fix cannon prediction bugs#891
Conversation
| } else { | ||
| ret = ret || ((cv->GetPointSurfaceDistance(static_cast<const CFeature*>(obj), nullptr, tstPos) - coneSize) <= 0.0f); | ||
| ret = ret || ((cv->GetPointSurfaceDistance(static_cast<const CFeature*>(obj), nullptr, hitPos) - coneSize) <= 0.0f); | ||
| CollisionQuery cq; |
There was a problem hiding this comment.
Also, if the weapon muzzle is inside a friendly unit, the shot is correctly blocked and does not fire.
There was a problem hiding this comment.
I see significant difference in Sim::Unit::Weapon occupation, does PR changes lie in the scope of that timer?
Do something representative of cannons in a regular game, perhaps a bit over the top. Spawn 20 berthas and 200 stumpies per side and let them duke it out? |
I agree this should be tested at massive scale. |
|
Right, the screenshots of I can do a test of two large cannon weapon armies fighting. And yes, it should lie in the scope of |
|
Try something long-range too, eg 100 berthas firing above 500 solars. If that doesn't get worse either then the change is probably alright. |
|
armbrtha (BAR Basilica) currently has |
|
Yes, "bertha" stands for "something with a half-map range so that it generates a lot of checks along the trajectory". |
|
The So one possible solution is to tie the factor to a property of the projectile itself such as the horizontal velocity A weapondef parameter to set the specific number of frames of end travel time to ignore could also address this issue |
|
Somehow this new method of testing has 16x less load in |
|
Ok, did the 10k HaveFreeLineOfFire loop. Throwing in a So 57% longer to perform a friendly fire check. |
|
Found one optimization: |
|
Doing:
Results in a net speedup compared to base engine: |
|
Sounds good, thanks a lot for thorough inspection! |
| #define go geometricObjects | ||
|
|
||
| // red line pointing to hitPos | ||
| go->SetColor(go->AddLine(pos, trajStartPos, 3, 0, GAME_SPEED), 1.0f, 0.0f, 0.0f, 1.0f); |
There was a problem hiding this comment.
the #define looks very meek?
| go->SetColor(go->AddLine(pos, trajStartPos, 3, 0, GAME_SPEED), 1.0f, 0.0f, 0.0f, 1.0f); | |
| geometricObjects->SetColor(geometricObjects->AddLine(pos, trajStartPos, 3, 0, GAME_SPEED), 1.0f, 0.0f, 0.0f, 1.0f); |
…velocity" This reverts commit e48acc2.
…. Correct staged change this time.
41c6b2b to
1c21706
Compare
| // quadratic parabolic coefficient is the ratio of gravity to (horizontal velocity)^2 | ||
| const float projectileSpeedHorizontal = projectileSpeed * launchDir.Length2D(); | ||
| const float projectileSpeedVertical = projectileSpeed * launchDir.y; | ||
| const float linCoeff = (projectileSpeedVertical + (gravity * 0.5f) ) / projectileSpeedHorizontal; //(gravity * 0.5f) is factor due to discrete acceleration steps |
There was a problem hiding this comment.
What if projectileSpeedHorizontal is 0? Think tremor or some other high-trajectory cannons with enough inaccuracy
There was a problem hiding this comment.
Good catch. :)
I'll be reviewing various zero conditions this week











There have been some long standing bugs in the HaveFreeLineOfFire step of cannon weapons.
This Pull Request corrects those calculation errors, setting the proper linear and quadratic parabolic coefficients and using the weapon muzzle instead of aimpoint.

Image shows a cannon shot perfectly following the predicted path.
And this pull request adds in a DetectHit check along the "chord" of the parabola to mitigate instances of units thinking their shot will clear the top of a friendly unit, but instead clipping the close or far corner of the friendly unit.

Image shows an artillery unit correctly not firing and clipping the corner of a friendly unit.
Chord checks are replacing GetPointSurfaceDistance calls, so performance impact should be minimal.
Engine still builds successfully for me with these edits.
This is my first PR to the Spring/Recoil repo, so advice and feedback is greatly appreciated :)