Page MenuHomeWildfire Games

Fix units sometimes turning around when fleeing (introduced by D1987/rP22431)
ClosedPublic

Authored by wraitii on Mon, Sep 9, 7:10 PM.

Details

Summary

D1987/rP22431 introduced logic to predict the target movement, which fixed unit chasing. However, sometimes fleeing units would then predict that their target end up in _front_ of them, so they turned around towards the attacker.

To fix this, we can check if we still predict the direction of movement to be the same. If not, don't try to anticipate.

Test Plan

This can be most easily tested with the macedonian lancer hunting deer.

Diff Detail

Repository
rP 0 A.D. Public Repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

wraitii created this revision.Mon, Sep 9, 7:10 PM
Vulcan added a comment.Mon, Sep 9, 7:12 PM

Successful build - Chance fights ever on the side of the prudent.

Link to build: https://jenkins.wildfiregames.com/job/vs2015-differential/114/display/redirect

Vulcan added a comment.Mon, Sep 9, 7:18 PM

Successful build - Chance fights ever on the side of the prudent.

Link to build: https://jenkins.wildfiregames.com/job/docker-differential/623/display/redirect

Stan added a subscriber: Stan.Tue, Sep 10, 1:24 PM
Stan added inline comments.
source/simulation2/components/CCmpUnitMotion.cpp
1090 ↗(On Diff #9685)

Are there any specific cmpPosition->GetPosition2D() where we can early return because we know it won't be the case ?

Freagarach accepted this revision.Tue, Sep 10, 1:24 PM
Freagarach added a subscriber: Freagarach.

Works like a charm! Thanks @wraitii ;D
I've tried to break this in several occasions but failed to do so, however, code-wise I've little knowledge about this part.

This revision is now accepted and ready to land.Tue, Sep 10, 1:24 PM
wraitii added inline comments.Tue, Sep 10, 1:25 PM
source/simulation2/components/CCmpUnitMotion.cpp
1090 ↗(On Diff #9685)

A dot product of 2 2D vectors is fairly cheap, so I don't think it's really worth trying.

Stan added inline comments.Tue, Sep 10, 1:27 PM
source/simulation2/components/CCmpUnitMotion.cpp
1082 ↗(On Diff #9685)

Could move that after the early return.

1090 ↗(On Diff #9685)

Alright :)