示例#1
0
    private void LadderMovement(Vector3 rawInput)
    {
        if (gotMoveInput)
        {
//			Vector3 inputDirection = Vector3.ProjectOnPlane(head.transform.TransformDirection(new Vector3(0f, 0f, rawInput.z)), ladderNormal);
//			Vector3 inputDirection = Vector3.ProjectOnPlane(head.transform.TransformDirection(rawInput), ladderNormal);
            Vector3 inputDirection = Vector3.ProjectOnPlane(head.transform.TransformDirection(new Vector3(rawInput.x * 0.33f, 0f, rawInput.z)), ladderNormal);                  //TODO don't do the *0.33f thing here. do something else...
            if (ownVelocity.magnitude <= moveSpeedRegular)
            {
                ownVelocity += inputDirection * moveAcceleration * Time.fixedDeltaTime;
                if (ownVelocity.magnitude > moveSpeedRegular)
                {
                    ownVelocity = ownVelocity.normalized * moveSpeedRegular;
                }
            }
            else
            {
                Vector3 idealVector    = inputDirection * moveSpeedRegular;
                Vector3 deltaV         = idealVector - ownVelocity;
                Vector3 velocityChange = deltaV.normalized * moveAcceleration * Time.deltaTime;
                if (velocityChange.magnitude > deltaV.magnitude)
                {
                    velocityChange = deltaV;
                }
                ownVelocity += velocityChange;
            }
        }
        else
        {
            Vector3 decelVector = ownVelocity.normalized * (-moveAcceleration) * Time.fixedDeltaTime;
            if (decelVector.magnitude > ownVelocity.magnitude)
            {
                decelVector = -ownVelocity;
            }
            ownVelocity += decelVector;
        }
        if (keyJump.GetKey())
        {
            if (Vector3.Dot(ladderNormal, head.transform.forward) > 0f)
            {
                ownVelocity += ladderNormal * 5;
            }
        }
        else
        {
            gravityVector = -ladderNormal * 0.1f;
        }
    }
示例#2
0
    private Vector3 GetInputVector()
    {
        int inputZ = (keyMoveForward.GetKey() ? 1 : 0) + (keyMoveBackward.GetKey() ? -1 : 0);
        int inputX = (keyMoveLeft.GetKey() ? -1 : 0) + (keyMoveRight.GetKey() ? 1 : 0);

        return(new Vector3(inputX, 0f, inputZ));
    }
示例#3
0
    private void SprintManager()
    {
        bool wantToSprint = false;

        if (keySprintHold.GetKey())
        {
            wantToSprint = true;
        }
        if (keySprintHold.GetKeyUp())
        {
            wantToSprint = false;
        }
        if (keySprintToggle.GetKeyDown())
        {
            wantToSprint = !wasSprinting;
        }
        if (wantToSprint && gotMoveInput && !isCrouching)
        {
            isSprinting = true;
        }
        else
        {
            isSprinting = false;
        }
        wasSprinting = isSprinting;
    }
示例#4
0
    private void CrouchManager()
    {
        bool isGoingToCrouch = wasCrouching;

        if (keyCrouchHold.GetKey())
        {
            isGoingToCrouch = true;
        }
        if (keyCrouchHold.GetKeyUp())
        {
            isGoingToCrouch = false;
        }
        if (keyCrouchToggle.GetKeyDown())
        {
            isGoingToCrouch = !wasCrouching;
        }
        if (!isGoingToCrouch && wasCrouching)
        {
            Vector3    rayOrigin = transform.position + (Vector3.up * col.height / 2f);
            float      rayLength = normalHeight - (col.height / 2f);
            RaycastHit hit;
            if (Physics.Raycast(rayOrigin, Vector3.up, out hit, rayLength, layermaskPlayer))
            {
                if (hit.collider.gameObject.layer != layerWater)
                {
                    isGoingToCrouch = true;
                    Debug.LogWarning("crouchcast hit " + hit.collider.name + ", layer " + LayerMask.LayerToName(hit.collider.gameObject.layer));
                }
            }
        }
        isCrouching = isGoingToCrouch;
        if (isCrouching && col.height > crouchHeight)
        {
            col.height = crouchHeight;
            col.center = new Vector3(0f, crouchHeight / 2f, 0f);
            head.transform.localPosition         = new Vector3(0f, crouchEyeLevel, 0f);
            waterTrigger.transform.localPosition = new Vector3(0f, crouchWaterTriggerPos, 0f);
            if (!isGrounded)
            {
                transform.position = transform.position + (Vector3.up * (normalHeight - crouchHeight) / 2f);
            }
        }
        if (!isCrouching && col.height < normalHeight)
        {
            col.height = normalHeight;
            col.center = new Vector3(0f, normalHeight / 2f, 0f);
            head.transform.localPosition         = new Vector3(0f, normalEyeLevel, 0f);
            waterTrigger.transform.localPosition = new Vector3(0f, normalWaterTriggerPos, 0f);
            if (!isGrounded)
            {
                transform.position = transform.position + (Vector3.down * (normalHeight - crouchHeight) / 2f);
            }
        }
        wasCrouching = isCrouching;
    }
示例#5
0
    //utility

    void ManageToggleAndHoldInput(ref bool value, DoubleKey keyHold, DoubleKey keyToggle)
    {
        if (keyHold.GetKey())
        {
            value = true;
        }
        if (keyHold.GetKeyUp())
        {
            value = false;
        }
        if (keyToggle.GetKeyDown())
        {
            value = !value;
        }
    }
示例#6
0
    Vector3 GetDirectionalInput()
    {
        int     keyboardZ       = (keyMoveForward.GetKey() ? 1 : 0) + (keyMoveBackward.GetKey() ? -1 : 0);
        int     keyboardX       = (keyMoveLeft.GetKey() ? -1 : 0) + (keyMoveRight.GetKey() ? 1 : 0);
        Vector3 keyboardInput   = new Vector3(keyboardX, 0f, keyboardZ);
        float   controllerX     = Input.GetAxisRaw("LX");
        float   controllerY     = Input.GetAxisRaw("LY");
        Vector3 controllerInput = new Vector3(controllerX, 0f, controllerY);
        Vector3 combined        = keyboardInput + controllerInput;

        if (combined.sqrMagnitude > 1f)
        {
            combined = combined.normalized;
        }
        return(combined);
    }
示例#7
0
 void FixedUpdate()
 {
     PlayerMovementNEW.MoveInput moveInput;
     if (!paused)
     {
         Vector3 dirInput = GetDirectionalInput();
         moveInput = new PlayerMovementNEW.MoveInput(dirInput, keyJump.GetKey(), isCrouching, isSprinting);
     }
     else
     {
         moveInput = new PlayerMovementNEW.MoveInput(Vector3.zero, false, isCrouching, isSprinting);
     }
     view.ExecuteFixedUpdate();
     movement.ExecuteFixedUpdate(moveInput);
     gui.SetInteractDisplayMessage(movement.DebugInfo);
     if (view.isHoldingOntoSomething)
     {
         view.ManageGrabbedObject();
     }
 }