When the NPC reaches within the SIGNIFICANT_CLIENT_MOVEMENT distance of the target, move it directly to the target.

This makes the movement exact.  Regression test changed to check avatar reaches exact target.
Also has the nice side effect of making NPC animations continue to work after the first movement (which wasn't working).  However, avatar still pauses in mid-stride
bulletsim
Justin Clark-Casey (justincc) 2011-08-04 01:00:33 +01:00
parent ba0c65e028
commit 7f6f100c5a
3 changed files with 7 additions and 3 deletions

View File

@ -1575,6 +1575,7 @@ namespace OpenSim.Region.Framework.Scenes
if (distanceToTarget <= 1) if (distanceToTarget <= 1)
{ {
// We are close enough to the target // We are close enough to the target
AbsolutePosition = MoveToPositionTarget;
ResetMoveToTarget(); ResetMoveToTarget();
updated = true; updated = true;
} }
@ -1713,7 +1714,7 @@ namespace OpenSim.Region.Framework.Scenes
/// </summary> /// </summary>
public void ResetMoveToTarget() public void ResetMoveToTarget()
{ {
// m_log.DebugFormat("[SCENE PRESENCE]: Resetting move to target for {0}", Name); m_log.DebugFormat("[SCENE PRESENCE]: Resetting move to target for {0}", Name);
m_moveToPositionInProgress = false; m_moveToPositionInProgress = false;
MoveToPositionTarget = Vector3.Zero; MoveToPositionTarget = Vector3.Zero;

View File

@ -70,12 +70,13 @@ namespace OpenSim.Region.OptionalModules.World.NPC
// presence.Name, presence.AbsolutePosition, presence.MoveToPositionTarget, distanceToTarget); // presence.Name, presence.AbsolutePosition, presence.MoveToPositionTarget, distanceToTarget);
// Check the error term of the current position in relation to the target position // Check the error term of the current position in relation to the target position
if (distanceToTarget <= 1) if (distanceToTarget <= 2)
{ {
// m_log.DebugFormat("[NPC MODULE]: Stopping movement of npc {0} {1}", presence.Name, presence.UUID); // m_log.DebugFormat("[NPC MODULE]: Stopping movement of npc {0} {1}", presence.Name, presence.UUID);
// We are close enough to the target for now // We are close enough to the target for now
presence.ResetMoveToTarget();
presence.Velocity = Vector3.Zero; presence.Velocity = Vector3.Zero;
presence.AbsolutePosition = presence.MoveToPositionTarget;
presence.ResetMoveToTarget();
// FIXME: This doesn't work // FIXME: This doesn't work
if (presence.PhysicsActor.Flying) if (presence.PhysicsActor.Flying)

View File

@ -130,6 +130,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
double distanceToTarget = Util.GetDistanceTo(npc.AbsolutePosition, targetPos); double distanceToTarget = Util.GetDistanceTo(npc.AbsolutePosition, targetPos);
Assert.That(distanceToTarget, Is.LessThan(1), "NPC not within 1 unit of target position on first move"); Assert.That(distanceToTarget, Is.LessThan(1), "NPC not within 1 unit of target position on first move");
Assert.That(npc.AbsolutePosition, Is.EqualTo(targetPos));
// Try a second movement // Try a second movement
startPos = npc.AbsolutePosition; startPos = npc.AbsolutePosition;
@ -149,6 +150,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
distanceToTarget = Util.GetDistanceTo(npc.AbsolutePosition, targetPos); distanceToTarget = Util.GetDistanceTo(npc.AbsolutePosition, targetPos);
Assert.That(distanceToTarget, Is.LessThan(1), "NPC not within 1 unit of target position on second move"); Assert.That(distanceToTarget, Is.LessThan(1), "NPC not within 1 unit of target position on second move");
Assert.That(npc.AbsolutePosition, Is.EqualTo(targetPos));
} }
} }
} }