- Home /
Player position with Joystick and Head Tracker
This is what I am trying to achieve. The player will move in the x,y,z direction using a joystick, I have this working already. Now I am trying to add head tracking, i.e the camera moves using a tracker on the players head. I have the position values coming in from the tracker fine. I want both the joystick and the head tracking to be working together.
However, what I am struggling with is combining the joystick input and the tracker input. Here is my script so far.
Vector3 move = Vector3.zero;
move.x = (leftController.JoystickX * xmovScale);
move.y = (rightController.JoystickY * ymovScale);
move.z = (leftController.JoystickY * zmovScale);
fpc.transform.Translate(move);
fpc.transform.position = new Vector3 ((rightController.Position.x) * headMoveScale, (rightController.Position.y) * headMoveScale, (rightController.Position.z) * headMoveScale);
and I apologise for the formatting, I can't get it correct.
You set the camera rotation by by accessing "`fpc.transform.rotation`". The real question is what is the nature of the input from the head tracker, and what kind of behavior do you want the camera to have?
@$$anonymous$$elly$$anonymous$$:
HeadTracking is usually more about offsetting the camera.
See this HeadTracking-video
However to get an effect like in this video you have to heavily adjust the projection matrix to get a view like this. However the basic principle stays the same. The headtracking system deter$$anonymous$$es your heads position in front of your screen so you can adjust the camera position in relation to your head.
If you really want to do what you've seen in the video you only have to work with the projection matrix. Usually your camera position is your virtual camera position which is at the players position and the near-clipping plane has a fix distance from the camera position and you have a certain fov.
With headtracking you have a fix near-clipping plane (at the players position) and using the tracking information to calculate the projection parameters to represent the cam position (your head). That's not so easy if you don't know how perspective projection works ;)
Ps: If you really want to do something like that, there are some threads around the net (use your google-fu).
Very good video, I imagining taking the heads rotation relative to a deadzone and using that to rotate the camera, i.e. player looks to the side of the screen and the camera turns to face that way. The effect in the video would be much more challenging to implement.
Answer by Bunny83 · Dec 13, 2013 at 01:14 PM
From your description and your code it's not really clear what you actually want to do. In your last line you set the position to an absolute value. You do this every frame so you can't add a relative motion to it since you reset it each frame.
I guess that you want the headtracking position as offset to your actual character position.
Since headtracking usually just affects the camera and not the player you could simply apply the tracking position to the localPosition of the camera only. So the camera still moves along with the player but gets an offset from the headtracking. Depending in which space you get your tracking information (probably in camera local space) you might have to transform the position into "local player space". However that soley dependy on what kind of game you actually have (fps, tps, 2.5d sidescroller, ...)