Ejemplo n.º 1
0
    /**
     * Gather inputs used to determine new camera values
     */
    public void Update()
    {
        //Ignore camera controls when typing in chat
        ChatWindow chatWindow = chatManager.GetChatWindow();

        if (chatWindow != null && chatWindow.PlayerIsTyping())
        {
            return;
        }

        // Check for double tap
        if (Input.GetButtonDown("Camera Rotation"))
        {
            prevHorizontalAxisPress = Time.time;
        }

        // If a double tap actually works
        // Round to closest 90 degree angle, going up or down based on whether axis is positive or negative
        if (Input.GetButtonUp("Camera Rotation") && (Time.time - prevHorizontalAxisPress) < CARDINAL_SNAP_TIME)
        {
            angle = Mathf.Round((angle + (Input.GetAxis("Camera Rotation") > 0 ? 45.1f : -45.1f)) / 90.0f) * 90.0f;
            prevHorizontalAxisPress = 0.0f;
            return;
        }

        // input handling
        float zoom        = Input.GetAxis("Camera Zoom");
        float angleDelta  = 0.0f;
        float vAngleDelta = 0.0f;

        if (Input.GetButton("Camera Rotation") && (Time.time - prevHorizontalAxisPress) > CARDINAL_SNAP_TIME)
        {
            angleDelta = Input.GetAxis("Camera Rotation") * HORIZONTAL_ROTATION_SENSITIVITY * Time.deltaTime;
        }
        if (Input.GetButton("Camera Vertical Rotation"))
        {
            vAngleDelta = Input.GetAxis("Camera Vertical Rotation") * VERTICAL_ROTATION_SENSITIVITY * Time.deltaTime;
        }

        // Camera mouse movement: On right click being held down
        if (Input.GetMouseButton(1)) // There isnt a f*****g enum for the mouse buttons
        {
            // Use mouse movement to determine axes
            angleDelta  = Input.GetAxis("Mouse X");
            vAngleDelta = -Input.GetAxis("Mouse Y");
        }

        // Determine new values, clamping as necessary
        distance = Mathf.Clamp(distance - zoom, MIN_DISTANCE, MAX_DISTANCE);
        angle    = (angle + angleDelta) % 360f;
        vAngle   = Mathf.Clamp(vAngle + vAngleDelta, MIN_VERTICAL_ANGLE, MAX_VERTICAL_ANGLE);
    }
Ejemplo n.º 2
0
        void Update()
        {
            ForceHeightLevel();

            //Must be the local player, or they cannot move
            if (!isLocalPlayer)
            {
                return;
            }

            //Ignore movement controls when typing in chat
            ChatWindow chatWindow = chatManager?.GetChatWindow();

            if (chatWindow != null && chatWindow.PlayerIsTyping())
            {
                currentMovement.Set(0, 0);
                return;
            }

            if (Input.GetButtonDown("Toggle Run"))
            {
                isWalking = !isWalking;
            }

            // TODO: Implement gravity and grabbing
            // Calculate next movement
            // The vector is not normalized to allow for the input having potential rise and fall times
            float x = Input.GetAxisRaw("Horizontal");
            float y = Input.GetAxisRaw("Vertical");

            // Smoothly transition to next intended movement
            Vector2 intendedMovement = new Vector2(x, y).normalized *(isWalking ? walkSpeed : runSpeed);

            currentMovement = Vector2.MoveTowards(currentMovement, intendedMovement, Time.deltaTime * ACCELERATION);

            // Move the player
            if (currentMovement.magnitude > 0)
            {
                // Determine the absolute movement by aligning input to the camera's looking direction
                Vector3 absoluteMovement =
                    currentMovement.y * Vector3.Cross(mainCamera.transform.right, Vector3.up).normalized +
                    currentMovement.x * Vector3.Cross(Vector3.up, mainCamera.transform.forward).normalized;
                // Move (without gravity). Whenever we move we also readjust the player's direction to the direction they are running in.

                characterController.Move((absoluteMovement * Time.deltaTime));
                transform.rotation = Quaternion.LookRotation(absoluteMovement);
            }
        }