Unity-Wiimote
Unity-Wiimote copied to clipboard
IR points in 3D world example
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.
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:
- Use
IRData::GetPointingPosition()
to get generalized pointer information from the Wiimote (the IRData object is retrieved fromWiimote::Ir
). - 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).
- 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) - 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.
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));
}
}
yeaahhh please that would be awesome
@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.