1 00:00:16,017 --> 00:00:16,600 PROFESSOR: OK. 2 00:00:16,600 --> 00:00:19,650 So at this point, we have our roller ball demo. 3 00:00:19,650 --> 00:00:22,470 Now, we would like to interface with the Kinect. 4 00:00:22,470 --> 00:00:26,250 To do this, we're going to use the simple Kinect Unity 5 00:00:26,250 --> 00:00:26,976 package. 6 00:00:26,976 --> 00:00:28,630 It's over here. 7 00:00:28,630 --> 00:00:31,560 So in the simple Kinect package there is a prefab. 8 00:00:31,560 --> 00:00:34,740 You can drag this prefab into your game 9 00:00:34,740 --> 00:00:38,440 and it will initiate the Kinect and do all the stuff that's 10 00:00:38,440 --> 00:00:39,190 required for that. 11 00:00:42,390 --> 00:00:48,660 So now, when I start my game, the Kinect will turn on. 12 00:00:48,660 --> 00:00:51,550 And it's not going to do anything yet 13 00:00:51,550 --> 00:00:55,560 because I haven't interfaced it. 14 00:00:55,560 --> 00:00:59,730 So, now I want my ball that we created previously 15 00:00:59,730 --> 00:01:01,890 to follow my right hand sign. 16 00:01:01,890 --> 00:01:08,550 So what we're going to do is go into our player 17 00:01:08,550 --> 00:01:10,170 and we're going to add a script. 18 00:01:10,170 --> 00:01:13,860 The script that we're going to add is the follow join. 19 00:01:13,860 --> 00:01:22,490 You can find it in scripts, no, Kinect stuff. 20 00:01:22,490 --> 00:01:24,720 There it is and follow join. 21 00:01:24,720 --> 00:01:30,350 So let's drag it on to our player, 22 00:01:30,350 --> 00:01:32,410 and then we need to fill out which 23 00:01:32,410 --> 00:01:33,660 object we would like to track. 24 00:01:37,610 --> 00:01:40,300 So in this case I'd like to follow my right hand. 25 00:01:40,300 --> 00:01:45,535 And you can find that I have a right hand object here. 26 00:01:45,535 --> 00:01:52,310 So you can drag this right hand object into the player 27 00:01:52,310 --> 00:01:53,060 controller script. 28 00:01:56,330 --> 00:01:59,570 So that's the tracked object. 29 00:01:59,570 --> 00:02:01,830 And now the ball should follow my right hand. 30 00:02:09,750 --> 00:02:11,610 So you can see it there in the scene. 31 00:02:11,610 --> 00:02:14,140 As I move my hand closer to the Kinect, 32 00:02:14,140 --> 00:02:16,150 it moves closer to the camera. 33 00:02:16,150 --> 00:02:18,520 In many gamines, this isn't what You'd want though. 34 00:02:18,520 --> 00:02:20,650 So inside that follow join script 35 00:02:20,650 --> 00:02:23,470 there is an to invert each access. 36 00:02:23,470 --> 00:02:26,540 Since the z-axis is one goes toward the camera, 37 00:02:26,540 --> 00:02:30,460 in this case, we're going to invert the z-axis. 38 00:02:30,460 --> 00:02:36,790 So now, when we click play, as I move my hand forward, 39 00:02:36,790 --> 00:02:39,440 the ball moves forward within the world space, 40 00:02:39,440 --> 00:02:47,320 and back, left, right, up, down, etc. 41 00:02:47,320 --> 00:02:50,480 So now, with my right hand, I can control the ball. 42 00:02:53,710 --> 00:02:57,002 All of the pick-ups should still work as they did before 43 00:02:57,002 --> 00:02:59,730 and the game can still be won. 44 00:02:59,730 --> 00:03:03,795 So I'm getting all the pick-ups with my right hand. 45 00:03:03,795 --> 00:03:08,070 Have to go back it up a little. 46 00:03:08,070 --> 00:03:10,890 It's just like using a mouse or arrow keys, but in 3D. 47 00:03:14,710 --> 00:03:16,387 So as you can see, that still works. 48 00:03:16,387 --> 00:03:18,847 Your turn. 49 00:03:18,847 --> 00:03:20,680 So now, let's say we want to track something 50 00:03:20,680 --> 00:03:23,491 other than our right hand. 51 00:03:23,491 --> 00:03:27,340 You can adjust this in the moving object parent. 52 00:03:27,340 --> 00:03:30,280 So I have a detect joint script attached to here 53 00:03:30,280 --> 00:03:32,830 and this has a track joint option. 54 00:03:32,830 --> 00:03:38,440 You can change this to be any joint you like. 55 00:03:38,440 --> 00:03:44,050 So let's say I want to do my left and. 56 00:03:44,050 --> 00:03:50,958 I'll select the hand left object, which is somewhere. 57 00:03:50,958 --> 00:03:51,954 There it is. 58 00:03:55,950 --> 00:03:59,430 And then, for the sake of making things make sense, 59 00:03:59,430 --> 00:04:02,290 rename my object to left hand object. 60 00:04:07,290 --> 00:04:09,820 So now that this is called left hand object, 61 00:04:09,820 --> 00:04:13,060 we want to make sure that the object attached to the player 62 00:04:13,060 --> 00:04:16,350 controller, follow join, is indeed the left hand object 63 00:04:16,350 --> 00:04:20,360 as is visible right here. 64 00:04:20,360 --> 00:04:25,900 So now when I click play, it should follow my left hand 65 00:04:25,900 --> 00:04:26,908 not my right hand. 66 00:04:29,836 --> 00:04:31,788 If the Kinect can find me. 67 00:04:31,788 --> 00:04:34,730 There it is. 68 00:04:34,730 --> 00:04:36,760 And so I can move my left hand forward, 69 00:04:36,760 --> 00:04:39,744 left, right, up, down, etc. 70 00:04:39,744 --> 00:04:41,744 So now, let's say we want to try multiple joints 71 00:04:41,744 --> 00:04:44,280 at the same time. 72 00:04:44,280 --> 00:04:47,510 This whole moving objects parent part can be duplicated. 73 00:04:47,510 --> 00:04:51,780 So Control D or Command D to duplicate. 74 00:04:51,780 --> 00:04:56,740 And we can now create a left had object and a right hand object. 75 00:04:56,740 --> 00:05:05,253 So let's go back to being hand-right and rename this. 76 00:05:11,670 --> 00:05:14,820 So I'm going to add another sphere to my scene 77 00:05:14,820 --> 00:05:18,560 in order to have another object for my game. 78 00:05:18,560 --> 00:05:22,100 So let's create a sphere. 79 00:05:22,100 --> 00:05:24,980 And then I'm going it so that my right hand follows this one 80 00:05:24,980 --> 00:05:27,536 since my left hand already follows the player. 81 00:05:30,434 --> 00:05:32,840 So in Kinect stuff, follow join. 82 00:05:32,840 --> 00:05:34,830 Drag it right on to that sphere. 83 00:05:37,480 --> 00:05:39,190 OK. 84 00:05:39,190 --> 00:05:41,910 So now, I want this to follow my right hand object, 85 00:05:41,910 --> 00:05:44,230 so I'm going to drag that in as my track joint. 86 00:05:47,014 --> 00:05:49,561 And now that sphere should follow my right hand, 87 00:05:49,561 --> 00:05:50,894 while the other follows my left. 88 00:06:01,280 --> 00:06:03,465 So I didn't set the invert option on that one 89 00:06:03,465 --> 00:06:05,270 though, so as I move forward, they 90 00:06:05,270 --> 00:06:08,920 each go in opposite directions. 91 00:06:08,920 --> 00:06:11,830 But otherwise, left and right work as you'd expect, 92 00:06:11,830 --> 00:06:13,190 and up and down. 93 00:06:13,190 --> 00:06:15,370 So let's say I want to try a different joint. 94 00:06:18,751 --> 00:06:23,905 Like, let's make my left hand object be my head. 95 00:06:23,905 --> 00:06:26,984 We'll go to that moving object parent , 96 00:06:26,984 --> 00:06:29,150 change it to head here. 97 00:06:29,150 --> 00:06:31,346 And let's rename this to head. 98 00:06:46,010 --> 00:06:49,053 Now, my right hand controls the sphere 99 00:06:49,053 --> 00:06:52,810 that we just added and my head controls the player. 100 00:06:52,810 --> 00:06:55,080 So, where is my right hand? 101 00:06:55,080 --> 00:06:56,980 There is my right hand. 102 00:06:56,980 --> 00:06:57,990 Where is my head? 103 00:06:57,990 --> 00:06:58,944 Can we see it? 104 00:06:58,944 --> 00:06:59,610 Can I get it in? 105 00:07:05,022 --> 00:07:08,470 It's down here. 106 00:07:08,470 --> 00:07:10,640 You can see it up on scene view. 107 00:07:10,640 --> 00:07:12,900 I'm struggling to get bearings. 108 00:07:16,716 --> 00:07:18,930 Oh, I never set invert axis. 109 00:07:18,930 --> 00:07:20,190 That would explain that. 110 00:07:23,557 --> 00:07:26,924 Probably going to-- 111 00:07:32,700 --> 00:07:36,768 It was on player, right? 112 00:07:36,768 --> 00:07:37,754 No, it was not. 113 00:07:37,754 --> 00:07:38,740 It was on the sphere. 114 00:07:57,480 --> 00:08:01,120 Hope I can re-enter myself in world space. 115 00:08:01,120 --> 00:08:02,600 There it is. 116 00:08:02,600 --> 00:08:07,510 So, as I move my head left and right, up and down, 117 00:08:07,510 --> 00:08:10,320 and my hand, they all go properly. 118 00:08:10,320 --> 00:08:13,290 Each object's position can be addressed by other objects. 119 00:08:13,290 --> 00:08:17,790 And so this is how you can gather your data to use however 120 00:08:17,790 --> 00:08:19,460 you like.