Example #1
0
        /// <summary>
        /// Adds a physical representation of the avatar to the Physics plugin
        /// </summary>
        public virtual void AddToPhysicalScene (bool isFlying, bool AddAvHeightToPosition)
        {
            //Make sure we arn't already doing this
            if (m_creatingPhysicalRepresentation)
                return;

            //Set this so we don't do it multiple times
            m_creatingPhysicalRepresentation = true;

            IAvatarAppearanceModule appearance = RequestModuleInterface<IAvatarAppearanceModule> ();
            if (appearance != null)
            {
                if (appearance.Appearance.AvatarHeight == 0)
                    appearance.Appearance.SetHeight ();

                if (appearance.Appearance.AvatarHeight != 0)
                    m_avHeight = appearance.Appearance.AvatarHeight;
            }

            PhysicsScene scene = m_scene.PhysicsScene;

            Vector3 pVec = AbsolutePosition;

            if(AddAvHeightToPosition) //This is here so that after teleports, you arrive just slightly higher so that you don't fall through the ground/objects
                pVec.Z += m_avHeight;

            m_physicsActor = scene.AddAvatar(Name, pVec, Rotation,
                                                 new Vector3 (0f, 0f, m_avHeight), isFlying, LocalId, UUID);

            scene.AddPhysicsActorTaint(m_physicsActor);
            m_physicsActor.OnRequestTerseUpdate += SendPhysicsTerseUpdateToAllClients;
            m_physicsActor.OnSignificantMovement += CheckForSignificantMovement;
            m_physicsActor.OnCollisionUpdate += PhysicsCollisionUpdate;
            m_physicsActor.OnPositionAndVelocityUpdate += PhysicsUpdatePosAndVelocity;
            m_physicsActor.OnCheckForRegionCrossing += CheckForBorderCrossing;

            m_physicsActor.OnOutOfBounds += OutOfBoundsCall; // Called for PhysicsActors when there's something wrong
            m_physicsActor.SubscribeEvents(500);
            m_physicsActor.Orientation = Rotation;

            //Tell any events about it
            if (OnAddPhysics != null)
                OnAddPhysics();

            //All done, reset this
            m_creatingPhysicalRepresentation = false;
        }