playMaker

Author Topic: [solved] Select or change state, by "looking at" with Oculus Rift.  (Read 6550 times)

Playnoob

  • Playmaker Newbie
  • *
  • Posts: 21
Hi,
I searched the forum and couldn't come up with a solution, so asking here.

I'm guessing there is a solution that does not involve actually getting head-tracking info, but I'm really as my name says- a noob at this, and certainly no coding skills.

What I want to achieve is:
- if when wearing the oculus rift, a person turns around and say a cube comes into view, and if he/she is "looking" at it for say 2 seconds... i.e if the cube is now center-screen, and the user has not moved their head for about 2 seconds, then a trigger can rotate the cube, or switch on a light etc.

I'd be really grateful if any member could attach a Playmaker node graph showing the logic.

Kind Regards.
« Last Edit: July 25, 2014, 06:22:41 PM by Playnoob »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Select or change state, by "looking at" with Oculus Rift.
« Reply #1 on: July 24, 2014, 12:11:18 PM »
Use a Raycast every frame coming from one of the cameras.

You should be able to layer mask on what you want to highlight and move to another state for the pause check. Such as something like Wait and Game Object Compare actions in a state.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Playnoob

  • Playmaker Newbie
  • *
  • Posts: 21
Re: Select or change state, by "looking at" with Oculus Rift.
« Reply #2 on: July 24, 2014, 12:23:26 PM »
Thanks Lane. You've pointed me in the right direction. Will update this thread in case I stumble! (Still learning game logic and playmaker)

Kind Regards.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Select or change state, by "looking at" with Oculus Rift.
« Reply #3 on: July 24, 2014, 12:31:43 PM »
Yup, no problem feel free to ask questions.

I did something like this but used a spherecast so it was easier to look at something. Raycasts are really thin so the further away you are from something the more difficult and unnatural it is to actually trigger the 'looking at this' event or whatever.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Playnoob

  • Playmaker Newbie
  • *
  • Posts: 21
Re: Select or change state, by "looking at" with Oculus Rift.
« Reply #4 on: July 24, 2014, 12:36:45 PM »
oh!
Ok I'll have to look into spherecast then, because yes, the project I have in mind will have an oculus rift wearer "standing" stationary in a 360 environment.

No movement, except for his/her head being able to turn.

So for example to "switch on" a lamp at the other end of the room, the raycast might not be effective?

I'll read more on sphere cast.
Thank you for the help.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Select or change state, by "looking at" with Oculus Rift.
« Reply #5 on: July 24, 2014, 12:45:42 PM »
The Raycast is fine, but its really thin so sometimes its easier to use a spherecast to make it easier to point at a vague area. You'll see what im talking about when you set it up. =)
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Playnoob

  • Playmaker Newbie
  • *
  • Posts: 21
Re: Select or change state, by "looking at" with Oculus Rift.
« Reply #6 on: July 24, 2014, 03:52:01 PM »
Ok I'll admit defeat.
I don't know where to begin to get this action working.

As in the attached picture... I have to set it up so when the level boots the player wearing the oculus rift is in the room.

Now if he/she "looks" at the bedside lamp for about a second or two, it turns on.

I'd try a lot more... but although in my head the logic sounds easy enough... to actually get it done via my lack of knowledge of Unity syntax and logic flow... is not so easy.

I'd like to learn via example, and if anyone could spare time and attach a node graph for me to investigate, I'll be really grateful.

Kind Regards.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Select or change state, by "looking at" with Oculus Rift.
« Reply #7 on: July 24, 2014, 04:53:44 PM »
A Raycast is just a little thing that goes from an origin point toward a direction vector.

The origin can be an object, which will be your rift camera.

The direction is a normalized vector3, so if you want it to go forward then you would put "1" in the Z slot and 0's for the X and Y. By selecting "Self" space instead of "World" space you'll be casting a Ray (or laser if you will) out into the scene toward wherever the rift is looking.

Now, if you check the every frame option its going to do this constantly. There isn't much point in doing this once, then stopping.

The options for storing data are vast, but you only need to store the Hit Object. The ray will eventually collide with something, when it does then it will store that object into a variable of your choosing. Just make a new empty GameObject variable and put it in the Hit Object slot. It's not necessary to define that variable yourself, just keep it empty. When the raycast hits something it will put whatever it hits into that variable. The lamp will need a collider.

You'll need to put the things that can be hit by this raycast onto a specific layer, then in the Layer Mask options define that layer so the ray only hits things on that layer, otherwise it will be putting walls and everything into your Hit Object variable and thats not what you want.

Now that you know what the player is looking at then you can send a message to do something. For starters forget the wait, just fire an event when in the Hit Event slot and go to a second state where you use a Send Event action to send an event to the Hit Object telling it do something.

On the lamp, the object with the collider, you'll add an FSM and two states, the Start state will be empty and there will be a transition to another state that has an Activate Game Object action on it with the light as the target. Add a Global Event for this state, its the one that you're sending from the other FSM.

tl;dr

Now when you look at something on the correct layer mask your raycast will hit it, store the object, fire the event, send the message to the object it hit, the other object will recieve it and activate the light.

I'll probably make a video tutorial about this soon since after I got about halfway through I realized its probably a little more intermediate of something to tackle.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Playnoob

  • Playmaker Newbie
  • *
  • Posts: 21
Re: Select or change state, by "looking at" with Oculus Rift.
« Reply #8 on: July 24, 2014, 06:17:43 PM »
Lane,
 Thank you so much for taking the time. Not many would do this, I truly appreciate it. I'm going to follow and sort out the pieces using the steps you've given.

I'd bought most of the plugins for visual scripting, and i'm glad I've decided to stay with playmaker because of this level of support and guidance.

Thank you.

Playnoob

  • Playmaker Newbie
  • *
  • Posts: 21
Re: Select or change state, by "looking at" with Oculus Rift.
« Reply #9 on: July 25, 2014, 03:10:49 AM »
Hi Lane,
I followed a good deal of your previous post, but got stuck here:

>> For starters forget the wait, just fire an event when in the Hit Event slot and go to a second state
What exact event should I fire? I tried Collision Enter, and also Became Visible, but I get an error...

>>where you use a Send Event action to send an event to the Hit Object telling it do something.
Again, what event is being sent.. i.e which event should it be?

>>On the lamp, the object with the collider, you'll add an FSM and two states, the Start state will be empty and there will be a transition to another state that has an Activate Game Object action on it with the light as the target. Add a Global Event for this state, its the one that you're sending from the other FSM...

What would the Global event be? I have tried various combinations of what I thought, intuitively, would be the correct events, but alas, the logic is too low-level in unity. While it does encourage thinking at the molecular level.. it does so at the expense of intuitiveness and creativity :)

Hope you'd help by showing an FSM so i can de-construct and follow.
Kind Regards

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Select or change state, by "looking at" with Oculus Rift.
« Reply #10 on: July 25, 2014, 10:31:59 AM »
Make a new event and use the checkbox to make it global, this lets you see it in the drop-down in every fsm so it's easy to pick.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Playnoob

  • Playmaker Newbie
  • *
  • Posts: 21
Re: Select or change state, by "looking at" with Oculus Rift.
« Reply #11 on: July 25, 2014, 05:19:11 PM »
With some more searching, I've found another interesting way to do this:
http://pocketcyclone.com/2013/09/10/dont-stare-at-me/

I've still not got it working, but posting it here so others who are new and as clueless as myself, might benefit.

Regards.

**edit**
After watching this playmaker tutorial,
and in combination with the above "View box" link, I can finally mark this thread: "solved"
:)
« Last Edit: July 25, 2014, 06:21:51 PM by Playnoob »