Example #1
0
    private void ack_move(int err, wire obj)
    {
        a_move ack = (a_move)obj;

        Debug.Log("a_move:" + err + ":" + ack.uid + ack.pos);
        int uid = ack.uid;

        if (Player.Instance.Uid == uid)
        {
            return;
        }
        ThirdPerson p = GetCharacter(uid);

        if (p == null)
        {
            Debug.Log("ASYC UID NULL:" + uid);
            return;
        }
        Vector3    pos = new Vector3();
        Quaternion rot = new Quaternion();

        Tool.ToNative(ref pos, ack.pos);
        Tool.ToNative(ref rot, ack.rot);
        p.MoveTo(pos, rot, false, false);
        Debug.Log("ack_move uid:" + uid + pos + rot);
    }
    void MoveController()
    {
        if (player == null)
        {
            return;
        }
        delta += Time.deltaTime;
        if (delta < 0.1f)
        {
            return;
        }
        delta -= 0.1f;
        Vector3    move_pos;
        Quaternion move_rot;
        bool       move_jump    = false;
        bool       move_crouch  = false;
        float      turn_X_speed = GameConfig.Instance.turn_X_speed;
        float      turn_Y_speed = GameConfig.Instance.turn_Y_speed;
        float      run_speed    = GameConfig.Instance.run_speed;
        //character rotation
        Quaternion rot    = player.transform.localRotation;
        float      mouseY = turn_Y_speed * InputManager.GetTurnY();
        float      mouseX = turn_X_speed * InputManager.GetTurnX();
        Quaternion rotY   = Quaternion.Euler(0.0f, mouseY, 0.0f);

        rot = rot * rotY;
        //position
        float   moveX = InputManager.GetMoveX();
        float   moveZ = InputManager.GetMoveZ();
        Vector3 move  = new Vector3(moveX, 0, moveZ);

        player_control.text = "input(x:" + move.x.ToString("F1") + ",z:" + move.z.ToString("F1") + ")";
        Vector3 forward = move * Time.deltaTime * run_speed * (0.1f / Time.deltaTime);

        forward  = rot * forward;
        move_pos = player.transform.position + forward;
        //control player
        var        srot   = player.Shadow.rot;
        var        angleX = srot.eulerAngles.x - mouseX;
        Quaternion rotX   = Quaternion.Euler(angleX, 0.0f, 0.0f);

        rot      = rot * rotX;
        move_rot = Tool.ClampRotationAroundXAxis(rot);
        //jump crouch
        move_jump = InputManager.GetJump();
        player.MoveTo(move_pos, move_rot, move_jump, move_crouch);
    }