Fix impact position for fast projectiles #4416
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes
Reasoning
When impacting a Thing, CanCollideWith() returns the distance
dto the Thing from the previous position of the projectile. This is then used to derive the point of impact by getting the point on the shotline that is exactlyddistance away from its origin (the previous position). The projectile's current position is then set to this point.Since #3907 added special-casing for when the projectile's current or previous position is already within the bounding box of the impacted Thing, this doesn't work correctly, because the special casing returns a distance of 0, so the projectile's current position is set back to its previous position following the above logic. Secondary effects such as fragments and explosions then spawn a few tiles behind.
This normalization logic also means that when impacting Things whose hitbox precisely lines up with a cell,
the projectile's final position would end up sitting precisely on a cell boundary. Since a
Vector3->IntVec3conversion is just(int)x, 0, (int)z, this position always corresponds to the cell due east or north of the boundary, which, when shooting south or west, would be the previous cell on the shotline. Since we always want explosion effects to occur in the impacted cell, we should shift the position accordingly if it is on a cell boundary.Testing
Check tests you have performed:
188, 0, 36(it's the rocky outcropping near some of the starting steel, east-southeast of the cannon).