예제 #1
0
 public static bool Attempt_Rotate_Entity(Entity entity, Vector3 target)
 {
     if(Network_Command_Manager.instance.socket.IsServer) {
         LocalRotateEntity(entity, target);
         return true;
     } else {
         SmartObject obj = new SmartObject();
         obj.AddString("type", "ROTATE_ENTITY");
         obj.AddEntity("Entity", entity.entity_model);
         obj.AddVec3("Target", target);
         Network_Command_Manager.instance.ToNetController<Client_Controller>().SendRequest(obj);
         return false;
     }
 }
예제 #2
0
    //    public static void Rotate_Entity(Entity entity, Vector3 target){
    //        target = target - entity.transform.position;
    //        target = new Vector3 (target.x, 0, target.z);
    //        Quaternion look_rotation = Quaternion.LookRotation (target);
    //        entity.transform.rotation = look_rotation;
    //    }
    public static void Attempt_Move_Entity(Entity entity, Vector3 target, System.Action<Entity_Model> action = null)
    {
        if(Network_Command_Manager.instance.socket.IsServer) {
            Seeker seeker = entity.GetComponent<Seeker>();
            seeker.StartPath(seeker.transform.position, target, delegate (Path path) {
                Vector3[] vecp = path.vectorPath.ToArray();
                if(vecp.Length > 1) {
                    Quaternion rotation;
                    Vector3 destination;
                    float moved;
                    PathFindAlong(entity.entity_model.stats.movement, vecp, out moved, out rotation, out destination);
                    entity.entity_model.stats.movement -= moved;
                    if(entity.entity_model.stats.movement < 0.1f)
                        entity.entity_model.stats.movement = 0;
                    if(moved <= 0)
                        return;
                    entity.transform.rotation = rotation;
                    entity.transform.position = destination;

                    entity.entity_model.pos = new Vector3_Serial(entity.transform.position);
                    entity.transform.rotation = Quaternion.Euler(new Vector3(0, entity.transform.rotation.eulerAngles.y, 0));

                    entity.entity_model.rot = new Vector3_Serial(entity.transform.rotation.eulerAngles);

                    action(entity.entity_model);
                }
            });
        } else {
            SmartObject obj = new SmartObject();
            obj.AddString("type", "MOVE_ENTITY");
            Debug.Log("sending move request");
            Debug.Log(target);
            obj.AddEntity("Entity", entity.entity_model);
            obj.AddVec3("Target", target);
            Network_Command_Manager.instance.ToNetController<Client_Controller>().SendRequest(obj);
        }
    }