コード例 #1
0
    private void StaggerHandler()
    {
        _staggerTimer += Time.deltaTime;

        switch (StaggerState)
        {
        case Constants.StaggerState.full:
            if (_staggerTimer >= Constants.STAGGER_FULL)
            {
                StaggerState  = Constants.StaggerState.none;
                _staggerTimer = 0;
            }
            break;

        case Constants.StaggerState.half:
            if (_staggerTimer >= Constants.STAGGER_HALF)
            {
                StaggerState  = Constants.StaggerState.none;
                _staggerTimer = 0;
            }
            break;

        case Constants.StaggerState.third:
            if (_staggerTimer >= Constants.STAGGER_THIRD)
            {
                StaggerState  = Constants.StaggerState.none;
                _staggerTimer = 0;
            }
            break;
        }
        ;
    }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        //ensure that all following code will be for the users player and not the others on the network.
        if (!isLocalPlayer)
        {
            return;
        }

        if (StaggerState != Constants.StaggerState.none)
        {
            StaggerHandler();
            return;
        }

        if (_isRolling)
        {
            LerpPosition();
            return;
        }


        // Generate a plane that intersects the transform's position with an upwards normal.
        var playerPlane = new Plane(Vector3.up, transform.position);

        // Generate a ray from the cursor position
        var ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        // Determine the point where the cursor ray intersects the plane.
        // This will be the point that the object must look towards to be looking at the mouse.
        // Raycasting to a Plane object only gives us a distance, so we'll have to take the distance,
        // then find the point along that ray that meets that distance.  This will be the point
        // to look at.
        var hitdist = 0.0f;

        // If the ray is parallel to the plane, Raycast will return false.
        if (playerPlane.Raycast(ray, out hitdist))
        {
            // Get the point along the ray that hits the calculated distance.
            var targetPoint = ray.GetPoint(hitdist);

            // Determine the target rotation.  This is the rotation if the transform looks at the target point.
            transform.rotation = Quaternion.LookRotation(targetPoint - transform.position);
        }

        float speed = SpeedBase;

        //handle sprint functionality
        if (_staminaManager.Stamina > 9.9 && (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)))
        {
            speed *= 2;
            _staminaManager.Decrease(30 * Time.deltaTime);
        }

        //handle input direction. This code may be adjusted in the future. It currently will only support 8 axis movement.
        //note that there appears to be a floaty feeling when moving. This may be due to my keyboard.
        //I was forced to use transform.position because transform.translate causes issues when the characters forward
        //vector is locked to the mouse position.
        if (Input.GetAxis("Horizontal") > 0 && Input.GetAxis("Vertical") > 0)
        {
            transform.position = transform.position + ((_rightAxis + _upAxis).normalized * speed * Time.deltaTime);
            lastDirection      = Constants.Direction.upright;
        }
        else if (Input.GetAxis("Horizontal") < 0 && Input.GetAxis("Vertical") > 0)
        {
            transform.position = transform.position + ((-_rightAxis + _upAxis).normalized * speed * Time.deltaTime);
            lastDirection      = Constants.Direction.upleft;
        }
        else if (Input.GetAxis("Horizontal") > 0 && Input.GetAxis("Vertical") < 0)
        {
            transform.position = transform.position + ((_rightAxis + -_upAxis).normalized * speed * Time.deltaTime);
            lastDirection      = Constants.Direction.downright;
        }
        else if (Input.GetAxis("Horizontal") < 0 && Input.GetAxis("Vertical") < 0)
        {
            transform.position = transform.position + ((-_rightAxis + -_upAxis).normalized * speed * Time.deltaTime);
            lastDirection      = Constants.Direction.downleft;
        }
        else if (Input.GetAxis("Horizontal") > 0 && Input.GetAxis("Vertical") == 0)
        {
            transform.position = transform.position + (_rightAxis * speed * Time.deltaTime);
            lastDirection      = Constants.Direction.right;
        }
        //note that the right axis is not negated. Instead it is subtracted. this is more efficient than negating a vector then adding.
        else if (Input.GetAxis("Horizontal") < 0 && Input.GetAxis("Vertical") == 0)
        {
            transform.position = transform.position - (_rightAxis * speed * Time.deltaTime);
            lastDirection      = Constants.Direction.left;
        }
        else if (Input.GetAxis("Horizontal") == 0 && Input.GetAxis("Vertical") > 0)
        {
            transform.position = transform.position + (_upAxis * speed * Time.deltaTime);
            lastDirection      = Constants.Direction.up;
        }
        else if (Input.GetAxis("Horizontal") == 0 && Input.GetAxis("Vertical") < 0)
        {
            transform.position = transform.position - (_upAxis * speed * Time.deltaTime);
            lastDirection      = Constants.Direction.down;
        }


        if (Input.GetMouseButtonDown(0))
        {
            CmdFire();
        }

        if (Input.GetMouseButtonDown(1))
        {
            NinjaRoll();
        }

        #region Degug Inputs
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            _staminaManager.Stamina = 100;
        }

        if (Input.GetKeyDown(KeyCode.Keypad1))
        {
            StaggerState = Constants.StaggerState.full;
        }

        if (Input.GetKeyDown(KeyCode.R))
        {
            Respawn();
        }
        #endregion
    }