Unity-Wiimote icon indicating copy to clipboard operation
Unity-Wiimote copied to clipboard

IR points in 3D world example

Open andreierdoss opened this issue 9 years ago • 4 comments

Thank you for your hard work. Would it be possible to give an example on representing IR points in 3D world ie. move and shoot. I want to use the Wiimote to shoot moving objects in the 3D world.

andreierdoss avatar Nov 03 '15 16:11 andreierdoss

I have written a demo with this functionality. It may take a while to get it polished and in master, though. For now I can offer you the general process:

  1. Use IRData::GetPointingPosition() to get generalized pointer information from the Wiimote (the IRData object is retrieved from Wiimote::Ir).
  2. Set up an empty game object as a child of the camera and put a textured quad in it as a child (this will be the crosshair).
  3. In your script use Camera.ViewportToWorldPoint() (with input X,Y=the pointing position from IRData and Z=how far you want the pointer to be from the camera)
  4. When you want to select something use Camera.ScreenPointToRay() and use raycasting to see what you are currently hovering over.

If you want to use this to interface with UI (you probably do) then you will want to create an InputModule for the Wiimote. You can reference Unity's PointerInputModule to see how they did it for mouse pointing.

Flafla2 avatar Nov 04 '15 03:11 Flafla2

Thank you for providing the steps. Bellow is the script that I attached to the Quad, but I'm getting errors. If you could post your demo in it's current state, I'm sure it would be useful to get me in a better position.

using UnityEngine;
using System.Collections;
using WiimoteApi;

public class ShotgunController : MonoBehaviour {
    private Wiimote wiimote;

    void Start () {
        WiimoteManager.FindWiimotes();
    }

    void Update () {
        if (!WiimoteManager.HasWiimote()) { return; }

        wiimote = WiimoteManager.Wiimotes[0];

        float[] pointer = wiimote.Ir.GetPointingPosition();
        Camera camera = GetComponent<Camera>();
        camera.ViewportToWorldPoint (new Vector3(pointer [0], pointer [1], 5));
    }
}

andreierdoss avatar Nov 11 '15 12:11 andreierdoss

yeaahhh please that would be awesome

0xWr41th avatar Nov 26 '15 02:11 0xWr41th

@Flafla2 I made a little project using the IR points in a 3D world. It's works pretty good, the only thing I didn't seem to figure out was limiting the camera angles. There is probably a simple solution for this, but this was the my first time working in Unity.

My Project

Haradrim avatar May 22 '16 16:05 Haradrim