Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#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)

faceTowardsPoint.diff (5.2 KB ) - added by mimo 11 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 by mimo, 11 years ago

Keywords: patch review added
Summary: weird roaming behaviour[PATCH] weird roaming behaviour

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.

by mimo, 11 years ago

Attachment: faceTowardsPoint.diff added

comment:2 by sanderd17, 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 mimo, 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 Philip Taylor, 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:5 by philip, 11 years ago

Owner: set to philip
Resolution: fixed
Status: newclosed

In 13924:

Fix #1833: animals spin around needlessly while roaming.

Patch from mimo.

comment:6 by Philip Taylor, 11 years ago

Keywords: review removed

(Thanks!)

comment:7 by leper, 11 years ago

Milestone: BacklogAlpha 15

comment:8 by RefinedCode, 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

A couple dozen times until the game crashes.

Last edited 11 years ago by RefinedCode (previous) (diff)

in reply to:  8 ; comment:9 by historic_bruno, 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 failed

A 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.

in reply to:  9 comment:10 by RefinedCode, 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 failed

A 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!

Note: See TracTickets for help on using tickets.