Example #1
0
    //controls player movement
    void Movement()
    {
        //check keyboard input
        //if (Input.anyKey)
        //{

        /**if (Input.GetMouseButton(1)) //Code for mouse movement, 100% needs to be optimized if used
         * {
         *  Vector2 mousePos = Camera.main.ScreenToViewportPoint(Input.mousePosition);
         *  Vector3 playerPos = Camera.main.WorldToViewportPoint(playerObject.transform.position);
         *
         *  Vector2 translateVector = mousePos - new Vector2(playerPos.x, playerPos.y);
         *  translateVector.Normalize();
         *  translateVector /= 10;
         *
         *  playerObject.transform.Translate(translateVector);
         * }**/

        Vector3 movement = Vector3.zero;

        //y movement

        if (Input.GetAxis("LeftStickY") != 0)
        {
            movement.y = Input.GetAxis("LeftStickY");
        }
        else if (Input.GetKey(KeyCode.W))
        {
            movement += Vector3.up;
        }
        else if (Input.GetKey(KeyCode.S))
        {
            movement += Vector3.down;
        }

        //x movement
        if (Input.GetAxis("LeftStickX") != 0)
        {
            movement.x = Input.GetAxis("LeftStickX");
        }
        else if (Input.GetKey(KeyCode.A))
        {
            movement += Vector3.left;
        }
        else if (Input.GetKey(KeyCode.D))
        {
            movement += Vector3.right;
        }

        if (Input.GetButton("Interact") && canInteract) //Begin Conversation/Interaction
        {
            canInteract   = false;
            isInteracting = true;
            interactingObject.Interact();
        }

        if (Input.GetButton("Special") && !isRolling) //It certainly is special
        {
            isRolling = true;
        }

        if (movement.magnitude > 1)
        {
            movement.Normalize();
        }
        transform.position += movement * speed * Time.deltaTime;
    }