Esempio n. 1
0
    private void WalkMove()
    {
        if (CheckJump())
        {
            //空中
            AirMove();
            return;
        }

        Friction();

        float fmove  = cmd.forwardmove;
        float smove  = cmd.rightmove;
        float upmove = cmd.upmove;

        if (fmove != 0 || smove != 0)
        {
            CLog.Info("move {0}, {1}", fmove, smove);
        }

        float scale = CMDScale(cmd);

        SetMovementDir();

        impl.forward[1] = 0;
        impl.right[1]   = 0;
        impl.forward.Normalize();
        impl.right.Normalize();

        Vector3 wishvel = new Vector3();

        for (int i = 0; i < 3; i++)
        {
            wishvel[i] = impl.forward[i] * fmove + impl.right[i] * smove;
        }
        wishvel[1] = 0;

        Vector3 wishdir   = wishvel;
        float   wishspeed = wishdir.magnitude;

        wishdir.Normalize();
        wishspeed *= scale;

        Accelerate(wishdir, wishspeed, pm_accelerate);

        //以下部分可以用物理引擎来计算
        if (impl.groundPlane)
        {
            ClipVelocity(ref playerState.velocity, Vector3.up, ref playerState.velocity, 1f);
        }

        float vel = playerState.velocity.magnitude;

        ClipVelocity(ref playerState.velocity, Vector3.up, ref playerState.velocity, 1.001f);

        playerState.velocity.Normalize();
        playerState.velocity = playerState.velocity * vel;
        if (upmove > 0f)
        {
            agent.AddForce(new Vector3(0f, upmove / upmove, 0f));
        }
        if (playerState.velocity[0] == 0 && playerState.velocity[2] == 0)
        {
            playerState.origin = agent.position;
            return;
        }

        //以下部分可以用物理引擎来计算
        agent.Move(playerState.velocity);
        playerState.origin = agent.position;

        // StepSlidMove(false);
    }