Forum Discussion
enzedda
11 years agoExplorer
Using the mouse buttons
Greetings to you all. My first post.
I have my dk2 and i have free Unity.
I have setup mydk2 and it is great.
I have placed the Oculus Unity4 integration into a simple new Unity scene and all views/navigation works on the DK2 as it should.
I can easily import my Max objects/animations into Unity.
My Unity scene consists of a couple of spheres that when clicked on with the mouse cause other functions to operate on other included game objects. Very simple stuff as I have never used a game engine before and never scripted before.
But..as soon as I add the Unity4 integration into the scene I cannot use the mouse to "click" on anything?
The Rift display does not seem to allow any usage of the mouse buttons within the Unity scene
Is this normal?
I saw that the "c" key gives one a mouse cursor in the rift display but I cannot fathom how to utilise this.
Is there something I should have disabled or changed?
As I said before, I have never scripted before but I use 3dsMax and can generally understand most 3d terms.
Is there something I should have read about this problem and where might I look for enlightenment?
I have my dk2 and i have free Unity.
I have setup mydk2 and it is great.
I have placed the Oculus Unity4 integration into a simple new Unity scene and all views/navigation works on the DK2 as it should.
I can easily import my Max objects/animations into Unity.
My Unity scene consists of a couple of spheres that when clicked on with the mouse cause other functions to operate on other included game objects. Very simple stuff as I have never used a game engine before and never scripted before.
But..as soon as I add the Unity4 integration into the scene I cannot use the mouse to "click" on anything?
The Rift display does not seem to allow any usage of the mouse buttons within the Unity scene
Is this normal?
I saw that the "c" key gives one a mouse cursor in the rift display but I cannot fathom how to utilise this.
Is there something I should have disabled or changed?
As I said before, I have never scripted before but I use 3dsMax and can generally understand most 3d terms.
Is there something I should have read about this problem and where might I look for enlightenment?
16 Replies
Replies have been turned off for this discussion
- virrorExplorerIts probably because of the changed camera. I have no idea how your click script looks like but im guessing your doing a raycast from the camera and forward. You probably have to change the script to use one of the rift cameras instead.
- JyakkuHonored GuestLike Virror said, it's probably a discrepancy between the stock Unity camera and the Oculus camera. I imagine you're doing something like a raycast or a built-in helper like ScreenPointToWorld, which is still fine, but you'll have to change where the cast is coming from, because in VR the direction your head is facing is not necessarily the direction your body is facing.
For all raycast operations, I find it easiest to cast the ray from the ForwardDirection GameObject, which is a child of the OVRPlayerController.
I hope this helps, and if you're still having trouble I'm sure we can help you out based on a code sample of your sphere clicking code. - weasel47Heroic ExplorerI suspect the OP is not using any custom code for mouse-clicking, but is simply using "OnMouseDown." Clicking on objects in VR is much more complicated than that, unfortunately. OnMouseDown assumes a single camera rendering to a 2D screen with a mouse cursor associated with it.
To the OP, if you're brand new to development, you might want to mess around with Unity for a bit longer without OVR before you jump into the deep end.
The other two responders are right that you will need to use Raycasting. If you want a visible cursor that's attached to the player's view but that moves independently, that needs to be implemented as well. The mouse cursor you know doesn't really exist within VR. For my own projects, I've been using a cross-hair that's attached directly to the center of the user's view, so the user moves their head to aim at things rather than the mouse. I have a script that does a RayCast from the middle of the user's view and if a button is being pressed (the left mouse button, for example), that script sends a message to whatever object the RayCast is hitting. - enzeddaExplorer
"weasel47" wrote:
I suspect the OP is not using any custom code for mouse-clicking, but is simply using "OnMouseDown." Clicking on objects in VR is much more complicated than that, unfortunately. OnMouseDown assumes a single camera rendering to a 2D screen with a mouse cursor associated with it.
To the OP, if you're brand new to development, you might want to mess around with Unity for a bit longer without OVR before you jump into the deep end.
The other two responders are right that you will need to use Raycasting. If you want a visible cursor that's attached to the player's view but that moves independently, that needs to be implemented as well. The mouse cursor you know doesn't really exist within VR. For my own projects, I've been using a cross-hair that's attached directly to the center of the user's view, so the user moves their head to aim at things rather than the mouse. I have a script that does a RayCast from the middle of the user's view and if a button is being pressed (the left mouse button, for example), that script sends a message to whatever object the RayCast is hitting.
Mr Weasel47 is probably the closest of guesses!
Actually it's much more simpler than that:
I Can use Unity and build simple scenes that work just fine in Unity. No probs there.
It's just that I cannot use the mouse with the Oculus/Unity integration loaded to point and click the mouse the way I can in Unity itself.
By the comments I've read, that's the way it is !
I can get an event started by using a collision to trigger the event but that means I have to bump into my "buttons
'instead of clicking on them. Very crude indeed!
I thought that it may be possible to use the mouse "normally" but probably not which seems a shame.
Raycasting? Where is that explained in any detail.
The Unity manual seems very brief of any details on this function.
Can anyone point me to the proper place or maybe a tutorial?
And how do others manage to include the mouse functions in their demos?
The DK1 Virtual theatre or some name like that had seats allocated with a mouse click.
The DK2 Desktop demo from Oculus allows you to click on height and start and end with the mouse pointer andLMB.
Thanks. - virrorExplorerRaycasting is pretty straight forward really, you just send a ray from a certain point in a certain direction and if the ray hits something you can get hold of the collided object and then do whatever you want with it. Just google "Unity raycast example" or whatever and you should get loads of good results. For getting the mouse press you should look at "Input.GetKey()" in the documentation, it returns true or false if a button is pressed or not and you can then send a raycast if you detect a button press.
- enzeddaExplorer
"virror" wrote:
Raycasting is pretty straight forward really, you just send a ray from a certain point in a certain direction and if the ray hits something you can get hold of the collided object and then do whatever you want with it. Just google "Unity raycast example" or whatever and you should get loads of good results. For getting the mouse press you should look at "Input.GetKey()" in the documentation, it returns true or false if a button is pressed or not and you can then send a raycast if you detect a button press.
Thanks virror,
I'll be doing some looking at those tutes!
I can use getkey no trobs even with the unity integration but I can't use the mouse functions (yet) with the integration.
I didn't realise that this was normal with the Rift.
But I do now,I guess.
So this raycasting idea is something I will follow on with.
Thanks to all. - virrorExplorerRaycasting is something you have to learn anyway, so might as well start with it at once : p
- enzeddaExplorer
"virror" wrote:
Raycasting is something you have to learn anyway, so might as well start with it at once : p
Yes indeed...
And many thanks for your previous post about the Raycast functions and the Input.GetKey() as well.
Slowly beginning to get it !!
And I thought that 3D modelling was complicated !
I seldom if ever play games. I wouldn't have much interest in Unity if it wasn't for my love of 3D and the Rift.
Just getting my Max objects into VR was the thing that has made me look at Unity.
By the way,scripting...if that's a correct term... in Max is a lot lot easier :)
Oh well. I've ordered a book that Cyberreality mentioned in a post. I'm sure that will help a virtual non-scripter like me! - virrorExplorerUnity also have their own learn section, you can check out the official tutorials there covering many aspects of game creation: http://unity3d.com/learn/tutorials/modules
- enzeddaExplorer
"virror" wrote:
Unity also have their own learn section, you can check out the official tutorials there covering many aspects of game creation: http://unity3d.com/learn/tutorials/modules
Hi Virror,
I've checked those out but I have difficulty learning with Youtube and Video tutes.
Much rather have a nice old book to study where I like.
I got this one "Learning C# by Developing Games with Unity 3D"...Just arrived actually.
Not much, if anything about Raycasting..as far as I can see (quick browse) but lots of other stuff.
But it looks Ok for me. a beginner at scripting !
Virror, do you have any books to recommend?
I have also gotten the program "Visual Actions" which is like a cheat drag and click editor !
It allows one to perform actions without scripting but again seems to have very little if anything to do with Raycasting :(
Raycasting so's to be able to use the mouse cursor as a..umm.. mouse cursor is my main goal in all of this.
Thanks for your support and help with this, Virror...and you others as well.
I am looking forward to getting into scripting now.
Visual actions seems a bit messy.
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
- 2 years ago