Forum Discussion
JAromando
11 years agoHonored Guest
Using Rift Headtracking to Move an Object
Hi everyone,
In part of my game, I am looking to create a something similar to pong. In this, I want the movement of the players head to move a cube/plane that acts as the paddle.
I will be doing this in a separate scene from the main game and just load the scene since it will act as a type of mini game.
I want to know how exactly I can make it where the cube/plane is in sync with the players head movement. I have some ideas, but I am not a complete expert when it comes to the rift so I was hoping for some more feedback.
Thank you for your time.
** I know somewhere on the forums there is probably an answer to my question, but I am on the way out of the house and thought this would be better.
In part of my game, I am looking to create a something similar to pong. In this, I want the movement of the players head to move a cube/plane that acts as the paddle.
I will be doing this in a separate scene from the main game and just load the scene since it will act as a type of mini game.
I want to know how exactly I can make it where the cube/plane is in sync with the players head movement. I have some ideas, but I am not a complete expert when it comes to the rift so I was hoping for some more feedback.
Thank you for your time.
** I know somewhere on the forums there is probably an answer to my question, but I am on the way out of the house and thought this would be better.
10 Replies
Replies have been turned off for this discussion
- hash280689Honored GuestHi.
I might have a couple of ideas which could help. I'm assuming that the paddle will be moving on ONE axis. So for example, you are looking at the pong game from a birds eye view, and the paddle you control is at the bottom of your view, moving left and right with your head movement.
To get things working, you could possibly try a couple of things.
One would be to use ray casting. So your pong game could take place on a plane, which you can assign a label to like 'PongLayer'. You then cast a ray from the position of the 'Centre Eye Anchor' in the OVRCameraRig.
The way I did this was to create a script and attach it to the CenterEyeAnchor with the following code:
[SerializeField] LayerMask layerMask;
void Update()
{
RaycastHit hit;
if (!Physics.Raycast(transform.position,transform.forward, out hit, layerMask))
return;
}
In the editor, the 'LayerMask' variable will be shown as a drop down list. Select the 'ponglayer' as the only layer for the ray to look out for. This way, the raycast will only return a hit if it hits the 'pong' layer.
From here, you can then use 'hit.point' to get the world space position of the ray hit. You could then have paddle object match the transform.position of hit.point.
However, this would be mean the paddle will go up and down as well as left and right. If you JUST want it to go left and right, you can use say something like
"paddle.transform.position = new Vector3(hit.point.x, constantYval, constantZval);" I'm sure you'll be able to experiment from there.
The other solution would be to get the Y rotation of the head tracking from CenterEyeAnchor.transfrom.rotation.y, and then convert that value to an X translation. Personally I think Ray cast solution will be robust.
There are probably more elegant solutions to this which I'd also love to hear about. For now just to get things working, try this solution.
Hope this helps
EDIT: Come to think of it, using 'paddle.transform.localPosition' might be more beneficial. You should use an empty game object called 'Pong Container' or something, then place your pong table and other pong objects within that game object. - JAromandoHonored GuestAnd if I wanted to allow the player to move it on both x and y axis? So it could go, up and down, left and right, and diagonal. Would that be still possible?
I basically want it as the player looking at the back of his block that is across from the other block hitting it back.
Example: Observing from behind a goalie. - hash280689Honored GuestAh OK!
It depends on how you want the paddle to behave. Let's assume that there is an invisible wall in front of you. The paddle moves up, down, left and right but always sticking to that wall?
If that is the case then you still do the raycasting stuff I mentioned above. You make the ray detect this invisible wall, and when the ray hit's that wall, the paddle is placed there.
[SerializeField] LayerMask layerMask;
[SerializeField] Transform paddle;
void Update()
{
RaycastHit hit;
if (!Physics.Raycast(transform.position,transform.forward, out hit, layerMask))
return;
if (paddle != null)
paddle.position = hit.point;
else
Debug.Log("Please Set Paddle");
}
Is this the effect you are after? - hash280689Honored GuestHere, hopefully this package should help
https://www.dropbox.com/s/rmsxmpmkz99zl7b/Hash_Raycast_Paint.unitypackage?dl=0
If you run the demo, you'll see that I've attached a script to Cenre Eye Anchor in the OVRCameraRig.
The thing you'll need to pay attention to is the 'Marker' bit. Don't worry about any of the texture stuff. This basically translate the position of the marker game object to where the Ray is hitting.
Have a play and hopefully this should help with what you need - JAromandoHonored GuestI am getting three errors involving the OVRCameraController when bringing up the demo.
http://i.imgur.com/oblAGgK.png?1 - hash280689Honored GuestHmmm that's odd. I built it with Oculus SDK version 0.4.3.1. Which version of Oculus SDK are you using?
If you delete the content of the OVR and plugins folder, and an reimport the the version of Oculus SDK you are using, then just create a new oculus camera and just copy the ray cast script to the new camera. The script is based on whatever object transform you place it on.
Therefore, worse comes to worse, just use the generic first person controller from Unity and attach the script to the camera just to see how it works. I'm sure the error you're getting is due to a conflict in versions, or due to me not exporting the whole SDK with the package - JAromandoHonored GuestAlright I got it running (it was a version issue), except now I do not see anything occurring visually when running the scene. I see the marker and the blue behind it, but shouldn't it translate when I move the camera direction? Or is it just hard to see do to the background color?
Thanks a lot for your help. Really appreciate it. - hash280689Honored GuestOk, have you
a) Placed the OVRCameraRig within the cube? I think if you set the world coordinate to 0, 5, 0 it should work.
b) Look at the script you have attached to the Centre Eye Anchor. Is the 'Marker' variable assigned? If not, just drag the 'marker' gameobject into it
c) make sure the paint colour is something like red. I think I set the planes to be blue at run time.
See image in link
https://www.dropbox.com/s/a40xx65ybso4h4w/Capture.PNG?dl=0 - JAromandoHonored GuestYes all that is set on my project. What exactly am I looking for? May be I missing that?
- hash280689Honored GuestOk, I think that means there can only be one of two things left to looks for (sorry this is taking so long!! I probably should have sent a more complete example)
1) Make sure that the layer of each of the planes is set to 'Paint Layer'
2) In the 'Ray Cast Paint' script in Center Eye Anchor, check that the layer mask is set to only look for the 'PaintLayer' layer. This basically tells the script what the ray should not ignore.
It should then start mapping the marker to where your ray hitting, and then painting a line on the plane where ever you look.
See screenshots
https://www.dropbox.com/s/uyb621bcmivlx8c/Untitled.png?dl=0
So basically once this is all working, you can do a similar thing for your ping pong bat, where the Bat game object would replace 'Marker'.
If you're still having issues then I'm not sure what else it could be. I'd be happy to do a screen share video call on Skype or something. It seems we live in different time zones (I'm in the UK) so it may be need some coordinating, but it would be much faster if I could see where you were exactly having trouble
I really hope this helps
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 1 year ago
- 3 years ago
- 12 years ago