Daggerfall Unity VR with the Vive Pro

Discuss coding questions, pull requests, and implementation details.
Post Reply
User avatar
InconsolableCellist
Posts: 100
Joined: Mon Mar 23, 2015 6:00 am

Re: Daggerfall Unity VR with the Vive Pro

Post by InconsolableCellist »

Awesome! I was able to work on the VR a bit last night, but it seems I'm encountered a weird bug where the camera will only report its position accurately once, and subsequent updates get cached values rather than the current ones. I'm trying to apply its position to a sibling (which will hold a persistent UI) but it's fighting me like crazy.

I think what you described will work great for the laser pointer though. I can get the local x,y offset and provide that to the UI element. A major component (that I'd likely have to add) would be having elements highlight on the equivalent of mouser over, to provide feedback for where the click is going to hit. Is there a base UI element class I could modify to add the ability to turn a highlight overlay on and off? There'd be some logic necessary for hoverOver, hoverOut, and then onClick, to have highlights turn on and off and provide click feedback.


Interkarma wrote: Thu May 31, 2018 3:32 am This turned into a much bigger job than I expected with lots of little follow-on things to fix. But I'm quite happy with the state of it and everything is in master.

The goal from my end was just to render the UI to an offscreen RenderTexture that can be used either for a traditional overlay like before or drawn to a diegetic output of some kind. Now we have that flexibility in base, and you can turn off the standard UI overlay at will and render UI wherever you like.

I think the next thing I'll add is the ability to feed in custom pointer coordinates so you can wire up to the motion controller "laser pointer". From a UI perspective is there something else you need me to address?

User avatar
InconsolableCellist
Posts: 100
Joined: Mon Mar 23, 2015 6:00 am

Re: Daggerfall Unity VR with the Vive Pro

Post by InconsolableCellist »

Nystul wrote: Thu May 31, 2018 11:03 am This is truly impressive. I had always played with the idea to try out to port a simple dfunity demo to vr but all the points and issues you mentioned above have scared the hell out of me.
You guys do an amazing job here, you rock!
It's always been in the back of my mind, and I even did it in a rudimentary way once: https://www.youtube.com/watch?v=iyxjNaX6hyg

However with Daggerfall Unity instead of just raw DFTFU and the waaaay better libraries now, I think it'll be achievable. But it'll definitely require a ton of work.

User avatar
Interkarma
Posts: 7236
Joined: Sun Mar 22, 2015 1:51 am

Re: Daggerfall Unity VR with the Vive Pro

Post by Interkarma »

InconsolableCellist wrote: Thu May 31, 2018 8:02 pm Is there a base UI element class I could modify to add the ability to turn a highlight overlay on and off? There'd be some logic necessary for hoverOver, hoverOut, and then onClick, to have highlights turn on and off and provide click feedback.
Each UI component has a "MouseOverBackgroundColor". Setting this will change the background colour only when mouse is over it. This might not do everything you want however, and could conflict with other background colours like quest items.

There's also an Outline class you could use to drop an outline around controls. You'd only need the one outline and you can size/scale it how you want. If you like, I'm happy to build outlining globally into the UI system so it can just be enabled when needed.

There's also a bunch of events on the screen component class, but not all UI controls are exposed outside of their intended window. I'd rather find a more global than start opening up hundreds of individual controls. :)

User avatar
InconsolableCellist
Posts: 100
Joined: Mon Mar 23, 2015 6:00 am

Re: Daggerfall Unity VR with the Vive Pro

Post by InconsolableCellist »

Interkarma wrote: Thu May 31, 2018 8:12 pm
InconsolableCellist wrote: Thu May 31, 2018 8:02 pm Is there a base UI element class I could modify to add the ability to turn a highlight overlay on and off? There'd be some logic necessary for hoverOver, hoverOut, and then onClick, to have highlights turn on and off and provide click feedback.
Each UI component has a "MouseOverBackgroundColor". Setting this will change the background colour only when mouse is over it. This might not do everything you want however, and could conflict with other background colours like quest items.

There's also an Outline class you could use to drop an outline around controls. You'd only need the one outline and you can size/scale it how you want. If you like, I'm happy to build outlining globally into the UI system so it can just be enabled when needed.

There's also a bunch of events on the screen component class, but not all UI controls are exposed outside of their intended window. I'd rather find a more global than start opening up hundreds of individual controls. :)
The background color could be a good placeholder; I'd say hold off on implementing outlining, since it seems pretty specific to this usecase, and I'd like to get further along before taking your time up with it. There are probably going to be a dozen things before then that I'll want to pester you about.

I'm also still re-obtaining my Unity legs. Am I right in thinking that if I very simply make an Update() { Debug.log(transform.position); } and then move the camera over time, it should absolutely be outputting the camera's offset? With VR the offset changes as you move around the play area, and I can clearly see the values updating in the Inspector, but the Debug.log spits out only cached values. I want to make sure I'm not doing something stupid.

User avatar
Interkarma
Posts: 7236
Joined: Sun Mar 22, 2015 1:51 am

Re: Daggerfall Unity VR with the Vive Pro

Post by Interkarma »

The camera itself doesn't really move, it's a child of the player and moves relative to that parent. If you attach that script with the Debug.Log() in Update() directly to the player object, you should see the position updating as they move through the world.

User avatar
InconsolableCellist
Posts: 100
Joined: Mon Mar 23, 2015 6:00 am

Re: Daggerfall Unity VR with the Vive Pro

Post by InconsolableCellist »

Interkarma wrote: Thu May 31, 2018 8:26 pm The camera itself doesn't really move, it's a child of the player and moves relative to that parent. If you attach that script with the Debug.Log() in Update() directly to the player object, you should see the position updating as they move through the world.
In the case of VR it's actually moving the camera relative to the parent, and the transform's positions in the inspector are continually changing. It's like the parent object is the anchor and the camera strays around it as the player physically walks around his room's play area.

User avatar
Interkarma
Posts: 7236
Joined: Sun Mar 22, 2015 1:51 am

Re: Daggerfall Unity VR with the Vive Pro

Post by Interkarma »

So yep, If you attach a script with Debug.Log(transform.position) in Update(), then it will always be reporting that objects position in world. If you're getting the same values back each time, not sure what's going wrong there.

Are you just using the usual SteamVR camera rig at this point?

User avatar
InconsolableCellist
Posts: 100
Joined: Mon Mar 23, 2015 6:00 am

Re: Daggerfall Unity VR with the Vive Pro

Post by InconsolableCellist »

Interkarma wrote: Thu May 31, 2018 8:47 pm So yep, If you attach a script with Debug.Log(transform.position) in Update(), then it will always be reporting that objects position in world. If you're getting the same values back each time, not sure what's going wrong there.

Are you just using the usual SteamVR camera rig at this point?
I started with the SteamVR camera rig but discovered that it's not entirely necessary. So my current plan is to swap out some things in PlayerAdvanced when the mod is activated. Currently I broke the prefab instance. I removed the SmoothFollower, added two Controllers (from the SteamVR library) as siblings of the Camera, and added a sibling GameObject that'll serve as a virtual player body, so that when you look down you can see some UI elements following you. (Similar to HotDogs, Handguns, and Hand Grenades.) I was thinking the health bar would be down near your chest, for starters, and maybe different UI elements would draw to different quads (I've made one called UIQuad that currently is the redirected target for the diegetic UI mode).

An interesting development: the Debug.Log(...) reports the cached valued up until I move the player with the PlayerMotor script. At that point it suddenly snaps to the new values, then caches them once I stop moving. So something must trigger a refresh or recalculation.

User avatar
Interkarma
Posts: 7236
Joined: Sun Mar 22, 2015 1:51 am

Re: Daggerfall Unity VR with the Vive Pro

Post by Interkarma »

InconsolableCellist wrote: Thu May 31, 2018 8:53 pm An interesting development: the Debug.Log(...) reports the cached valued up until I move the player with the PlayerMotor script. At that point it suddenly snaps to the new values, then caches them once I stop moving. So something must trigger a refresh or recalculation.
Are you moving with teleport? My feeling is the VR rig is moving the camera around while the teleport is moving the player object. Is the Debug.Log() script attached to the player or the camera in this case?

Something that might help is just to attach a visible primitive like a cube or capsule to same object as Debug.Log() script. That way you can physically see the position in VR as well. The two should always line up, I'm not aware of Unity using any transform caching. It should always report the current position as of that frame.

User avatar
InconsolableCellist
Posts: 100
Joined: Mon Mar 23, 2015 6:00 am

Re: Daggerfall Unity VR with the Vive Pro

Post by InconsolableCellist »

Interkarma wrote: Thu May 31, 2018 9:31 pm
InconsolableCellist wrote: Thu May 31, 2018 8:53 pm An interesting development: the Debug.Log(...) reports the cached valued up until I move the player with the PlayerMotor script. At that point it suddenly snaps to the new values, then caches them once I stop moving. So something must trigger a refresh or recalculation.
Are you moving with teleport? My feeling is the VR rig is moving the camera around while the teleport is moving the player object. Is the Debug.Log() script attached to the player or the camera in this case?

Something that might help is just to attach a visible primitive like a cube or capsule to same object as Debug.Log() script. That way you can physically see the position in VR as well. The two should always line up, I'm not aware of Unity using any transform caching. It should always report the current position as of that frame.
Yeah, you're going down a similar path as I did. I have a thin cylinder that marks the central axis of the camera object, around which I want a UI element to rotate only in the Y direction, so that the player can look down and see the UI.

In this case there are three types of movement: teleport (I have it reposition the PlayerAdvanced), physical VR walking (translates and rotates the camera), and player motor with WASD (not used for VR, but I discovered that walking in this manner updates the camera's scipt-reported position as a side-effect).

The camera has to be the child of a GameObject to be able to move it around the world, as you're prevented from manually setting the translation's position and rotation on that camera once VR is activated. So as I have it now, the PlayerAdvanced is like a locus around which the camera translates, within the confines of your physical space. This is how the CameraRig prefab for SteamVR sets it up too.

Edit: You can see a similar idea here, where the player looks down and sees attachment points that follow his camera around, but which he can look down and inspect: https://www.youtube.com/watch?v=EgtSzSFEkis&t=19m20s

Post Reply