[Opensim-users] NPCs DoMoveToPosition vs DoAutoPilot

Teravus Ovares teravus at gmail.com
Thu Oct 28 15:54:48 UTC 2010


You need to pump avatar movement updates for the autopilot code to work.

Even if there are no movement flags, calling ScenePresence.HandleAgentUpdate
with a proper AgentUpdateArgs will 'move' the avatar a step towards the
target of the autopilot.

The following code is for an older version of OpenSimulator but it might
work with a few modifications on the current version.
(AddRegion is INonSharedRegionModule.AddRegion)

private int m_agentupdatepump = 5;
private Scene m_scene;
private List<ScenePresence> m_activeCharactersSP;
private List<Character> m_activeCharacters;

private Quaternion fourtyFiveDegreeAngle = new
Quaternion(0,0,-0.70711f,0.70711f);


public virtual void AddRegion(Scene scene)
{
    m_scene = scene;
    m_scene.EventManager.OnFrame += EventManager_OnFrame;
}

 void EventManager_OnFrame()
{
     m_frame++;

     if ((m_frame % m_agentupdatepump) == 0)
     {
          PumpAgentUpdate();
     }

     if (m_frame >= (int.MaxValue - 1))
     {
          m_frame = 0;
     }
 }

void PumpAgentUpdate()
{
     lock (m_activeCharacters)
     {
         foreach (Character c in m_activeCharacters)
         {
              ScenePresence cSP = m_scene.GetScenePresence(c.AgentId);
              PumpAgentUpdate(c, cSP);
         }
     }
}

void PumpAgentUpdate(Character pC, ScenePresence pSP)
{
     AgentUpdateArgs updateargs = new AgentUpdateArgs();
     updateargs.AgentID = pC.AgentId;

     updateargs.BodyRotation = Vector3.RotationBetween(Vector3.UnitX,
Vector3.Normalize(pC.m_lastTarget - pSP.AbsolutePosition));

     if (pC.ClientSideOrientation == fourtyFiveDegreeAngle)
         pC.ClientSideOrientation = Quaternion.Identity;

     updateargs.CameraAtAxis = Vector3.Zero;
     updateargs.CameraCenter = new Vector3(pSP.AbsolutePosition  - (new
Vector3(0,0,1) * updateargs.BodyRotation));
     updateargs.CameraLeftAxis = Vector3.Zero;
     updateargs.CameraUpAxis = Vector3.Zero;
     updateargs.ControlFlags = uint.MinValue;//
+(uint)OpenMetaverse.AgentManager.ControlFlags.AGENT_CONTROL_FLY;
     updateargs.Far = 128f;
     updateargs.Flags = byte.MinValue;
     updateargs.HeadRotation = Quaternion.Identity;
     updateargs.SessionID = pC.SessionId;
     updateargs.State = byte.MinValue;

     pSP.HandleAgentUpdate(pC,updateargs);
}


Note that the Character class had NPC related stuff in it like 'last
target'.   We need that information to send a proper BodyRotation in the
AgentUpdateArgs
updateargs.BodyRotation = Vector3.RotationBetween(Vector3.UnitX,
Vector3.Normalize(Character.m_lastTarget - ScenePresence.AbsolutePosition));

Hopefully, I've given you enough code to get started.


Teravus

On Wed, Oct 27, 2010 at 4:47 PM, bodzette Coignet <bodzettecoignet at gmail.com
> wrote:

> After some hair pulling and running into someone with complementary skills
> I've made some progress:
> I've managed to get a server side NPC to do the following:
> Rezz, Say something, Play an Animation and Delete itself.
>
> Unfortunately at the moment I can't get it to move and am currently
> investigating why not. Right now my understanding of things is somewhat
> limited so forgive me if my questions sound stupid to those in the know:
>
> A couple questions:
>
> Given that the NPC code appears to use a bunch of different autopilot code,
> I'm guessing that this is specific to NPCs and is not the way regular
> avatars move. It appears to be broken somehow, because the code is called
> but the NPC doesn't move. What is the difference between movement for a
> regular avatar and an NPC? It's my position that there really shouldn't be
> one, but could someone fill me in?
>
> What is the code that moves a standard (i.e. non-NPC avatar) is it
> Region.Framework.Scenes.ScenePresence.DoMoveToPosition or is it somewhere
> else?
>
> What is a ScenePresence? Is it that portion of a scene corresponding to a
> single avatar? If so is there any reason why an NPC avatar should exhibit
> different behavior here than a regular avatar?
>
> Can anyone give a program flow of how a regular avatar moves?
> My guess is it's something like this:
>  Intecerpt Arrow Key or Movement Control Arrow ->
> Pass avatar UUID and force and vector to server ->
> server finds avatar in scene (looping through scene dictionary of avatars
> till it identifies the right one?) ->
> server applies force and vector to appropriate avatar in dictionary ->
> avatar enters, does and completes movement ->
> server updates entire scene x times per second until avatar movement is
> completed
>
> Anyone verify the flow?
>
> Thanks in advance.
>
> _______________________________________________
> Opensim-users mailing list
> Opensim-users at lists.berlios.de
> https://lists.berlios.de/mailman/listinfo/opensim-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://opensimulator.org/pipermail/opensim-users/attachments/20101028/e77ee093/attachment.html>


More information about the Opensim-users mailing list