#1833 closed defect (fixed)
[PATCH] weird roaming behaviour
Reported by: | mimo | Owned by: | philip |
---|---|---|---|
Priority: | Should Have | Milestone: | Alpha 15 |
Component: | Core engine | Keywords: | patch |
Cc: | Patch: |
Description
When looking at roaming animals, their behaviour looks a bit weird, with the animals sometimes turning around themselves before going to a random direction. This behaviour is due to the fact that, in CCmpUnitMotion, any move is followed by a FaceTowardsPoint. That's nice in most of the cases, but not for roaming where animals move away from a point : thus the roaming is a succession of "move away from one point, turn back towards that previous point, then move away from the present point, ...". That would be better if we could remove the step "turn back towards that previous point". I suppose it would be nice to add a new member to CCmpUnitMotion m_FaceTowardsPoint = true by default, with a setter to be able to change it from UnitAI.js when necessary, and condition the calls to the FaceTowardsPoint method to it. That would allow more flexibility.
Attachments (1)
Change History (11)
comment:1 by , 11 years ago
Keywords: | patch review added |
---|---|
Summary: | weird roaming behaviour → [PATCH] weird roaming behaviour |
by , 11 years ago
Attachment: | faceTowardsPoint.diff added |
---|
comment:2 by , 11 years ago
I agree the behaviour looks a rather strange, and should be fixed. But I wonder if it requires a C++ fix.
Currently, the roaming requires the animal to move to a certain range of his current position. It would be just as simple to let it move to a fixed point instead. Just take a random angle, a random distance and take that point. It would make the code cleaner instead of abusing that "move to range" command IMO.
comment:3 by , 11 years ago
The advantage of this movetorange is that it deals cleanly with cases where the point is not accessible. That's may-be not so important for the random move, but that's a very clean solution for the flee and as I said, we may also want to not have this FaceTowardsPoint for fleeing skittish animals. In addition, for this ticket I've only implemented a yes-no option for the animals, but we may also think to more options. For ships for example, we could have two attacks types, one is ramming the other ship (where we should face it), but the other one is shooting to an other ship or to land units where a 90deg rotation would be nicer.
comment:4 by , 11 years ago
I think picking a random target point would probably be bad for roaming, because it'll often pick an unreachable point (which has bad performance in the current pathfinder, and wouldn't look like good roaming behaviour), and if a unit gets into a narrow gap then it'll probably get stuck there for a long time. Moving away from the current location ensures there's always somewhere for it to go, so it avoids those issues.
This patch seems to me like a reasonable solution to the immediate problem here.
comment:7 by , 11 years ago
Milestone: | Backlog → Alpha 15 |
---|
follow-up: 9 comment:8 by , 11 years ago
This patch is now giving me the error:
JavaScript error: simulation/components/UnitAI.js line4592 TypeError cmpMotion.SetFacePointAfterMove is not a function (true)@simulation/components/UnitAI.js:4592 ()@simulation/components/UnitAI.js:2439 ([object Object], "")@simulation/components/UnitAI.js:362 ([object Object])@simulation/components/UnitAI.js:2643 Script message handler OnDestroy failed
follow-up: 10 comment:9 by , 11 years ago
Replying to RefinedCode:
This patch is now giving me the error:
JavaScript error: simulation/components/UnitAI.js line4592 TypeError cmpMotion.SetFacePointAfterMove is not a function (true)@simulation/components/UnitAI.js:4592 ()@simulation/components/UnitAI.js:2439 ([object Object], "")@simulation/components/UnitAI.js:362 ([object Object])@simulation/components/UnitAI.js:2643 Script message handler OnDestroy failedA couple dozen times until the game crashes.
Have you built the game since that revision? It has some C++ changes that require a new build, and anyone who uses the autobuild will need to wait for that.
comment:10 by , 11 years ago
Replying to historic_bruno:
Replying to RefinedCode:
This patch is now giving me the error:
JavaScript error: simulation/components/UnitAI.js line4592 TypeError cmpMotion.SetFacePointAfterMove is not a function (true)@simulation/components/UnitAI.js:4592 ()@simulation/components/UnitAI.js:2439 ([object Object], "")@simulation/components/UnitAI.js:362 ([object Object])@simulation/components/UnitAI.js:2643 Script message handler OnDestroy failedA couple dozen times until the game crashes.
Have you built the game since that revision? It has some C++ changes that require a new build, and anyone who uses the autobuild will need to wait for that.
Didn't notice the C++ changes, thanks for clearing that up!
I attach a patch for that. I've applied it for the roaming state, but it could also be applied for skittish animals fleeing: after fleeing, they should not face their attacker, but stay ready to flee farther if necessary.