Example #1
0
    public void Update()
    {
        if (isStart == false)
        {
            //  Debug.Log("game not start characterController");
            return;
        }

        if (roleIsDie)   //玩家死亡不再时行操作
        {
            return;
        }

        float pDeltaTime = Time.deltaTime;

        float leftright = Input.GetAxis("Horizontal");
        float downup    = Input.GetAxis("Vertical");
        bool  isfire    = Input.GetButton("Fire1");
        bool  isSetJump = Input.GetButton("Jump");

        //test();

        if ((roleIsEscape == false)) //不逃跑并正在攻击中
        {
            if (roleIsAttack)
            {
                leftright = 0.0f;
                downup    = 0.0f;
                isfire    = true;
            }
        }
        else
        {
            isfire = false;
        }

        float offsetY = 0.0f;

#if usejump
        if (mainRoleState.getRoleNowState() == RoleStateMgr.roleState.jump)   //跳跃状态中
        {
            mainRoleState.addAllJumpTime(pDeltaTime);
            float allTime = mainRoleState.getAllJumpTime(); //已经跳的时间
            if (allTime <= csJumpUpTime)                    //计算人物坐标系中跳的高度
            {                                               //上升中
                float nowY = 0.5f * jumpA * allTime * allTime;
                offsetY = nowY - oldY;
                oldY    = nowY;
            }
            else
            {
                if (jumpCheck.isUse == false)   //开始下降,启用自由落体
                {
                    jumpCheck.isUse = true;
                    Rigidbody roleRigid = roleInstance.transform.GetComponent <Rigidbody>();
                    roleRigid.constraints = RigidbodyConstraints.FreezeRotation; //启用自由落体
                }

                /*
                 * if (jumpCheck.enabled)  //判断是否落地, 下落中
                 * {
                 *  float t1 = allTime - csJumpUpTime; ////计算下降了多长时间
                 *  float downY = 0.5f * jumpA * t1 * t1; //下落的距离
                 *  float nowY = csJumpHeightMax - downY;
                 *  offsetY = nowY - oldY;
                 *  oldY = nowY;
                 *
                 *  offsetY = 0.0f;
                 * }
                 * else { //已落地,由碰撞触发机制,不在update中执行
                 *
                 * }
                 */
            }
        }

        bool isChangeToJump = mainRoleState.updataRoleControl(leftright, downup, isfire, isSetJump); //按键改变角色动作状态

        if (isChangeToJump)                                                                          //起跳
        {
            Rigidbody roleRigid = roleInstance.transform.GetComponent <Rigidbody>();

            roleRigid.constraints    = RigidbodyConstraints.FreezePositionY;
            roleRigid.freezeRotation = true;
            oldY = 0.0f; // jumpStartY;
        }
#else
        //目前不使用跳跃功能
        mainRoleState.updataRoleControl(leftright, downup, isfire, false);
#endif

        if ((leftright != 0.0f) || (downup != 0.0f) || (offsetY != 0.0f))            //角色是否有位移
        {
            rolePosCamer.updateRolePosWorld(leftright, downup, pDeltaTime, offsetY); //改变角色位置及朝向, 基于世界坐标

            drawSceneAlpha();                                                        //场景虚化处理
                                                                                     //rolePosCamer.updateRolePos(tmpv,h); //改变角色位置, 基于roleControl, 暂不考虑

            //判断并取消破坏物件判定,之后的考虑

            //更改摄像机位置, 基于人的世界坐标
            //   rolePosCamer.updateCamerChartPos(roleInstance.transform, leftright, downup);  //摄像机判断并跟随
            //rolePosCamer.moveCamerWSADWorldPosFromControlMat(leftright, downup);
        }



#if camerdebug
        //摄相机平行场景 上下左右移动
        float camerleftRight = Input.GetAxis("HorizontalCamer");
        float camerDownUp    = Input.GetAxis("VerticalCamer");
        if ((camerleftRight != 0.0f) || (camerDownUp != 0.0f))
        {
            // rolePosCamer.moveCamerWSADWorldPosFromControlMat(camerleftRight, camerDownUp);
            rolePosCamer.moveCamerWSADWorldPosFromCamerControlMat(camerleftRight, camerDownUp, pDeltaTime);
        }
#endif
        //计算摄相机是否要进行旋转

        float camerRotationY = Input.GetAxis("CamerRotationY");
        if (camerRotationY != 0.0f)
        {
            rolePosCamer.rolationCamerY(camerRotationY, pDeltaTime);

            drawSceneAlpha(); //场景虚化处理
        }

#if camerdebug
        float camerRotationZ = Input.GetAxis("CamerRotationZ");
        if (camerRotationZ != 0.0f)
        {
            rolePosCamer.rolationFromRoleZ(camerRotationZ, pDeltaTime);
        }
#endif

        //人物拉进拉远
        float camerScale = Input.GetAxis("CamerScale");
        if (camerScale != 0.0f)
        {
            rolePosCamer.scaleCamer(camerScale, pDeltaTime);
        }
    }
Example #2
0
    public void Update()     //手动输入检测
    {
        if (isStart == false)
        {
            //  Debug.Log("game not start characterController");
            return;
        }


        if (mainRoleState.selfIsLive() == false)   //玩家死亡不再时行操作
        {
            return;
        }



        float pDeltaTime = Time.deltaTime;

        float leftright = Input.GetAxis("Horizontal");
        float downup    = Input.GetAxis("Vertical");

        float offsetY = 0.0f;

        if (mainRoleState.enemyObj != null) //有敌人
        {
            leftright = 0.0f;
            downup    = 0.0f;
        }

        //目前不使用跳跃功能,根据输入来修改主角的动作状态
        mainRoleState.updataAIRoleControl(leftright, downup, 0);


        if ((leftright != 0.0f) || (downup != 0.0f) || (offsetY != 0.0f))            //角色有位移
        {
            rolePosCamer.updateRolePosWorld(leftright, downup, pDeltaTime, offsetY); //改变角色位置及朝向, 基于世界坐标

            //drawSceneAlpha(); //场景虚化处理

            //更改摄像机位置, 基于人的世界坐标
            //   rolePosCamer.updateCamerChartPos(roleInstance.transform, leftright, downup);  //摄像机判断并跟随
            //rolePosCamer.moveCamerWSADWorldPosFromControlMat(leftright, downup);
        }



#if camerdebug
        //摄相机平行场景 上下左右移动
        float camerleftRight = Input.GetAxis("HorizontalCamer");
        float camerDownUp    = Input.GetAxis("VerticalCamer");
        if ((camerleftRight != 0.0f) || (camerDownUp != 0.0f))
        {
            // rolePosCamer.moveCamerWSADWorldPosFromControlMat(camerleftRight, camerDownUp);
            rolePosCamer.moveCamerWSADWorldPosFromCamerControlMat(camerleftRight, camerDownUp, pDeltaTime);
        }
#endif
        //计算摄相机是否要进行旋转

        float camerRotationY = Input.GetAxis("CamerRotationY");
        if (camerRotationY != 0.0f)
        {
            rolePosCamer.rolationCamerY(camerRotationY, pDeltaTime);

            //drawSceneAlpha(); //场景虚化处理
        }

#if camerdebug
        float camerRotationZ = Input.GetAxis("CamerRotationZ");
        if (camerRotationZ != 0.0f)
        {
            rolePosCamer.rolationFromRoleZ(camerRotationZ, pDeltaTime);
        }
#endif

        //人物拉进拉远
        float camerScale = Input.GetAxis("CamerScale");
        if (camerScale != 0.0f)
        {
            rolePosCamer.scaleCamer(camerScale, pDeltaTime);
        }
    }