void HandleMoveInput()
    {
        //If there is no movement script, leave
        if (playerMovement == null)
        {
            return;
        }

        //If there is a touchpad...
        if (touchPad != null)
        {
            //...get the direction of any movement touch that exists...
            Vector2 movement = touchPad.GetDirection();
            //...tell the movement script to move on the X and Z axes with no Y axis movement
            playerMovement.MoveDirection = new Vector3(movement.x, 0, movement.y);
        }
        //If there is a MouseLocation script and the mouse's position is valid...
        if (MouseLocation.Instance != null && MouseLocation.Instance.IsValid)
        {
            //Find the point the player should look at by subtracting the player's position from the mouse's position
            Vector3 lookPoint = MouseLocation.Instance.MousePosition - playerMovement.transform.position;
            //Tell the player what direction to look
            playerMovement.LookDirection = lookPoint;
        }
    }
Example #2
0
    void FixedUpdate()
    {
        // Keyboard controls:
        //float moveHorizontal = Input.GetAxis("Horizontal"),
        //      moveVertical = Input.GetAxis("Vertical");
        //Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);

        // Accelerometer controls:
        //Vector3 acceleration = calibrationQuaternion * Input.acceleration;
        //Vector3 movement = new Vector3(acceleration.x, 0.0f, acceleration.y);

        // Touchpad controls:
        Vector2 direction = touchpad.GetDirection();
        Vector3 movement  = new Vector3(direction.x, 0.0f, direction.y);

        rb.velocity = movement * speed;
        rb.position = new Vector3(
            Mathf.Clamp(rb.position.x, boundary.xMin, boundary.xMax),
            0.0f,
            Mathf.Clamp(rb.position.z, boundary.zMin, boundary.zMax));
        rb.rotation = Quaternion.Euler(0.0f, 0.0f, rb.velocity.x * tilt);
    }