예제 #1
0
파일: JumpState.cs 프로젝트: NoctisRB/Eddy
    private Vector3 CheckResidualCollisions()
    {
        var  vector3D          = Vector3.zero;
        var  t                 = _controller.transform;
        var  fForward          = _controller.feetOverlap.forward;
        var  fRight            = _controller.feetOverlap.right;
        var  sword             = _controller.scannerSword;
        bool _backForceApplied = false;

        if (CheckFloor(PlayerUtils.GetResidualColliders(_controller, _controller.feetOverlap.position - fForward * 0.5f, sword)))
        {
            vector3D.x += t.forward.x;
            vector3D.z += t.forward.z;
        }
        else if (_onEnemy)
        {
            vector3D.x       += t.forward.x * 0.5f;
            vector3D.z       += t.forward.z * 0.5f;
            _backForceApplied = true;
        }

        if (CheckFloor(PlayerUtils.GetResidualColliders(_controller, _controller.feetOverlap.position - fForward * 0.5f + fRight * 0.25f, sword)))
        {
            vector3D.x += t.forward.x * 0.5f;
            vector3D.z += t.forward.z * 0.5f;
            vector3D.x -= t.right.x * 0.5f;
            vector3D.z -= t.right.z * 0.5f;
        }

        if (CheckFloor(PlayerUtils.GetResidualColliders(_controller, _controller.feetOverlap.position - fForward * 0.5f - fRight * 0.25f, sword)))
        {
            vector3D.x += t.forward.x * 0.5f;
            vector3D.z += t.forward.z * 0.5f;
            vector3D.x += t.right.x * 0.5f;
            vector3D.z += t.right.z * 0.5f;
        }

        if (CheckFloor(PlayerUtils.GetResidualColliders(_controller, _controller.feetOverlap.position - fForward * 0.5f + fRight * 0.5f, sword)))
        {
            vector3D.x -= t.right.x;
            vector3D.z -= t.right.z;
        }

        if (CheckFloor(PlayerUtils.GetResidualColliders(_controller, _controller.feetOverlap.position - fForward * 0.5f - fRight * 0.5f, sword)))
        {
            vector3D.x += t.right.x;
            vector3D.z += t.right.z;
        }

        if (CheckFloor(PlayerUtils.GetResidualColliders(_controller, _controller.feetOverlap.position - fForward, sword)))
        {
            vector3D.x += t.forward.x;
            vector3D.z += t.forward.z;
        }

        if (CheckFloor(PlayerUtils.GetResidualColliders(_controller, _controller.feetOverlap.position + fRight * 0.5f, sword)))
        {
            vector3D.x -= t.right.x * 0.25f;
            vector3D.z -= t.right.z * 0.25f;
        }

        if (CheckFloor(PlayerUtils.GetResidualColliders(_controller, _controller.feetOverlap.position - fRight * 0.5f, sword)))
        {
            vector3D.x += t.right.x * 0.25f;
            vector3D.z += t.right.z * 0.25f;
        }

        if (CheckFloor(PlayerUtils.GetResidualColliders(_controller, _controller.feetOverlap.position + fForward * 0.5f, sword)))
        {
            if (!PlayerUtils.HasObjectInFront(_controller, t.position, t.forward))
            {
                if (_onEnemy && !_backForceApplied)
                {
                    vector3D.x -= t.forward.x * 0.5f;
                    vector3D.z -= t.forward.z * 0.5f;
                }
                else
                {
                    vector3D.x += t.forward.x;
                    vector3D.z += t.forward.z;
                }
            }
        }

        if (_onEnemy && !_backForceApplied)
        {
            vector3D.x -= t.forward.x;
            vector3D.z -= t.forward.z;
        }

        //Other positions can be added here. But just checking the back solves the major problem.

        if (vector3D != Vector3.zero)
        {
            vector3D = vector3D.normalized * _residualCollisionAvoidanceSpeed;
        }
        return(vector3D.normalized);
    }