SetPosition() public method

public SetPosition ( ScriptRuntime pos ) : void
pos ScriptRuntime
return void
 static public int SetPosition(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 2)
         {
             GameFramework.MovementStateInfo self = (GameFramework.MovementStateInfo)checkSelf(l);
             ScriptRuntime.Vector3           a1;
             checkValueType(l, 2, out a1);
             self.SetPosition(a1);
             pushValue(l, true);
             return(1);
         }
         else if (argc == 4)
         {
             GameFramework.MovementStateInfo self = (GameFramework.MovementStateInfo)checkSelf(l);
             System.Single a1;
             checkType(l, 2, out a1);
             System.Single a2;
             checkType(l, 3, out a2);
             System.Single a3;
             checkType(l, 4, out a3);
             self.SetPosition(a1, a2, a3);
             pushValue(l, true);
             return(1);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
        private void MoveNpc(EntityInfo obj, long deltaTime)
        {
            if (obj.HaveState(CharacterPropertyEnum.x3002_昏睡) ||
                obj.HaveState(CharacterPropertyEnum.x3001_眩晕))
            {
                return;
            }
            MovementStateInfo msi = obj.GetMovementStateInfo();

            //npc执行移动时忽略阻挡与避让,这些行为由ai模块在规划其路径时执行。
            if (!obj.IsDead() && obj.CanMove && msi.IsMoving)
            {
                ScriptRuntime.Vector3 pos = msi.GetPosition3D();
                float speed               = (float)obj.ActualProperty.GetFloat(CharacterPropertyEnum.x2011_最终速度);
                float distance            = (speed * (float)(int)deltaTime) / 1000.0f;
                ScriptRuntime.Vector3 dir = msi.TargetDir;

                //LogSystem.Debug("MovementSystem npc:{0} speed:{1} deltaTime:{2} distance:{3}", obj.GetId(), speed, deltaTime, distance);

                float x = 0, y = 0;
                if (msi.CalcDistancSquareToTarget() < distance * distance)
                {
                    x = msi.TargetPosition.X;
                    y = msi.TargetPosition.Z;
                    ScriptRuntime.Vector2 newPos = new ScriptRuntime.Vector2(x, y);
                    msi.SetPosition2D(newPos);
                    msi.IsMoving = false;
                }
                else
                {
                    ScriptRuntime.Vector3 tpos = pos + dir * distance;
                    msi.SetPosition(tpos);
                }
            }
        }
Example #3
0
        public void SyncSpatial()
        {
            if (null != m_Entity && null != Actor)
            {
                MovementStateInfo   msi = m_Entity.GetMovementStateInfo();
                UnityEngine.Vector3 v3  = Actor.transform.position;
                msi.SetPosition(v3.x, v3.y, v3.z);
                float dir = Utility.DegreeToRadian(Actor.transform.localEulerAngles.y);
                msi.SetFaceDir(dir);
                msi.SetMoveDir(dir);

                if (msi.IsMoving)
                {
                    Vector3 tpos = new Vector3(msi.TargetPosition.X, msi.TargetPosition.Y, msi.TargetPosition.Z);
                    if ((tpos - v3).sqrMagnitude < c_StopDistSqr)
                    {
                        msi.IsMoving = false;
                        if (null != Animator)
                        {
                            //Animator.CrossFade(c_StandAnim, c_CrossFadeTime);
                            Animator.Play(c_StandAnim);
                            msi.IsMoving = false;
                        }
                    }
                }
            }
        }
Example #4
0
 public void SyncPosition()
 {
     if (null != m_Entity && null != Actor)
     {
         MovementStateInfo   msi = m_Entity.GetMovementStateInfo();
         UnityEngine.Vector3 v3  = Actor.transform.position;
         msi.SetPosition(v3.x, v3.y, v3.z);
     }
 }
        private void MoveNpc(EntityInfo obj, long deltaTime)
        {
            if (obj.IsHaveStateFlag(CharacterState_Type.CST_Sleep) ||
                obj.IsHaveStateFlag(CharacterState_Type.CST_FixedPosition))
            {
                return;
            }
            MovementStateInfo msi = obj.GetMovementStateInfo();

            //npc执行移动时忽略阻挡与避让,这些行为由ai模块在规划其路径时执行。
            if (!obj.IsDead() && obj.CanMove && msi.IsMoving && !msi.IsSkillMoving)
            {
                ScriptRuntime.Vector3 pos = msi.GetPosition3D();
                float speed               = (float)obj.GetActualProperty().MoveSpeed;
                float distance            = (speed * (float)(int)deltaTime) / 1000.0f;
                ScriptRuntime.Vector3 dir = msi.TargetDir;

                //LogSystem.Debug("MovementSystem npc:{0} speed:{1} deltaTime:{2} distance:{3}", obj.GetId(), speed, deltaTime, distance);

                float x = 0, y = 0;
                if (msi.CalcDistancSquareToTarget() < distance * distance)
                {
                    x = msi.TargetPosition.X;
                    y = msi.TargetPosition.Z;
                    ScriptRuntime.Vector2 newPos = new ScriptRuntime.Vector2(x, y);
                    msi.SetPosition2D(newPos);

                    msi.IsMoving = false;
                    User user = obj.CustomData as User;
                    if (null != user)
                    {
                        Msg_RC_NpcMove npcMoveBuilder = DataSyncUtility.BuildNpcMoveMessage(obj);
                        if (null != npcMoveBuilder)
                        {
                            Scene scene = user.OwnRoom.ActiveScene;
                            if (null != scene)
                            {
                                scene.NotifyAllUser(RoomMessageDefine.Msg_RC_NpcMove, npcMoveBuilder);
                            }
                        }
                    }
                }
                else
                {
                    ScriptRuntime.Vector3 tpos = pos + dir * distance;
                    msi.SetPosition(tpos);
                }
            }
        }