Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

XBox controller, force, direction

Discussion in 'Input System' started by Peterj76, Jun 7, 2021.

  1. Peterj76

    Peterj76

    Joined:
    Nov 28, 2015
    Posts:
    7
    Hi,

    I have been making a Sling Shot style 'Angry Bird' style game. via Mouse, you can click down onto the bird, drag it, release it and it fires off in the direction with force. All works as expected.

    I am trying to implement this with XBOX controller. . After a LOT of mucking around, I finally have it you can press the X Botton to grab the bird, use the left stick to position (pull back) the bird, and releasing the button fires.

    The two main issue I have though, is, the Bird is Not firing in the right direction, nor taking the draw back distance into consideration.

    If you run the game and only use the controller, the bird flops to the ground. .Interestingly, if I have a shot with the mouse, and then use the joystick, it seems to fire the bird off 'not 'in the direction you set using the controller, but in the direction of the last shot using the mouse.

    Without going into too much detail. it's controlled something like this

    var pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    dis = pos - pivot.position;
    dis.z = 0;

    if (dis.magnitude > springRange)
    {
    dis = dis.normalized * springRange;
    }

    transform.position = dis + pivot.position;



    What I need help with, is how can I swap out the Input.mousePosition reference with my joysticks X and y axis within the ScreenToWorld command