How to Create a Whiteboard in Unity VR

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today i'm gonna show you how to make a whiteboard  so let me show you what we're going to make today   so you get a little idea for what we're doing  and then we'll jump into the tutorial here's   my little classroom scene that i have set up for  us this is just an asset pack that i downloaded   from the interwebs you'll see i have created a  little marker here and it is what we're going to   use to draw on this white board so you can color  the tip of this marker and whatever color you   make it that's the color that your marker will  actually draw on the whiteboard and you can adjust   the size of the marker as well and so as you can  see you can just draw whatever so vr and my frame   rate's a little sketchy just because i have a lot  of applications open on my computer right now but   ideally yours should be fine there we go a vr  whiteboard we're going to start completely from   scratch so i'm going to open up a new project this  is going to be 2021.1.20 is the version i'm using   any version 2020.3 and above should work the  same i'm just going to go with normal 3d this   is going to be a whiteboard tutorial we've loaded  our default 3d scene i'm actually going to set up   vr at the end of this video just to show you how  i usually test things because vr it's a little bit   of a hassle to actually test things so we're  going to do this just from what we have here   then we're going to add a vr in afterwards after  we have already done all the coding and whatnot   i will show you how to do every single line  of code in this video and show you how to do   everything but if you can't seem to get to work  or if you don't feel like writing in all the code   my patreon is linked below and you can download  the project straight from there so without further   ado let's get into it so we're going to need two  things one is a white board so we're going to   do a just a normal plane this one can actually  be the ground and then we're going to create a   capsule just so that we have a player reference  going to be a player size reference and i'm   going to bring that up so capsule is 2 meters  so this would be a 6 foot tall person just so   we can kind of reference how big we want to make  things and then i'm going to make a another plane   and this one is going to be our whiteboard  so i'm going to reset the whiteboard down   and then i'm going to rotate it 90 degrees move  it backwards a tad and the center point up a tad   and then we're actually going to scale this  down to something like 0.1 and let's say 0.3   or the the y-axis can stay one because it's going  to be a one thickness and then point three can be   the actual size there we go so a decent little  size white board here and this is what we're   actually gonna write on and it's important that  it's a plane because the method that we're going   to do actually will draw on all sides of the  texture so we only want one side of texture   visible for this style of white boarding and then  we also need a marker so we're going to create a   cube 3d object well first we're going to create  a empty object this is going to be called marker   and then we're going to make sure this is centered  make sure the cube is centered and then drag the   cube into the marker the cube can actually be  labeled like a handle or something like that   and we're gonna make sure to grab the marker  object and then drag and drop it next to our   player so we can get a size reference and then  the handle can be something like 0.1 by 0.3 by 0.1   could likely even go smaller than that and do  something like 0.05 by 0.3 by 0.05 there we go   so this is going to be the handle of our marker  and then we want to just duplicate that so i'm   going to click on handle and press ctrl d and then  rename this to the tip and then drag and drop that   up resize the y-axis to like point one maybe 0.05  and then if i want to link it directly to the top   of the handle i'm going to hold down the v key v  is in victor and that will let me snap to you'll   see there's this little box so it lets me snap  to a vertice and that will snap the tip to the   actual handle part of the marker and then one more  thing i want to add in is just a grab point so i'm   going to create a new empty object and say grab  point is its name and then we're just going to   manipulate the grab points so that the x-axis is  pointing forwards or up rather and you can kind of   angle this a little bit as well so your pin when  you're holding it is at a little bit of an angle   like you would normally when you're writing i'm  just gonna do it straight vertical because that's   uh the easiest way to kind of get started you  can always manipulate this a little bit later   and then i'm gonna drag and drop the grab point  a little higher as well so like a normal normal   pencil so like when you are a pen when you hold  a pen you're grabbing it at this point right here   and it's usually off at a little bit of an angle  so this is where you would kind of manipulate that   and then the tip we want to be able to color so  inside of our assets folder i'm going to create   a new folder called whiteboard and i'm just going  to throw all of the materials scripts prefabs into   this folder and this is actually for y'all so  you can download it later if you like from the   patreon link so we're going to create a another  folder this is going to be a materials folder   and then let's create a material inside of here  and this is just going to be let's say marker blue and then make that a uh kind of blue color and  then just drag and drop the material onto the   tip here there we go and you can kind of design  this a little more if you want make the felt   part a little smaller make it look more like a  marker turn this into a cylinder or something   but in this case we're just doing really simple  stuff just to kind of show you how it works you   can get creative with it in your your own time all  right we can actually delete our player stand in   now and then i'm gonna take our marker and move  it so it's right in front of the whiteboard when   we start testing we can just use the scene mode  and kind of drag and drop it along the whiteboard   so we need two scripts and the first one is pretty  simple so we're going to start with that one   so i'm going to create a scripts folder and  then let's create a whiteboard script so new   c-sharp script whiteboard and then double-click  to open it i'm using jetbrains writer which is   my favorite ide but it is a paid ide so everything  that i do in here will also work in visual studio   visual studio code it should all work the same  if something's not working for you just make   sure you have the same using statements i have  up here at the top i'll try to kind of say what   i'm adding or removing or whatnot so we don't need  this update method so i'm going to delete that and   then i'm just going to delete this comment as well  we're first going to want to access the texture   of this whiteboard so that we can manipulate it  so i'm going to say public texture 2d and then   we're just going to call it texture and then we  want the resolution so this is actually going   to be the texture size this is going to be public  vector 2 and we're going to call it texture size   and we're actually going to go ahead and set that  as well just so it is pre-existing and a designer   can come in later and manipulate the size so  this is going to be a new vector 2 and this is   going to be a 20 48 by 2048 to start out  with and then this will be the equivalent of   1 or 0.1 or something like that so you can you  know kind of scale the resolution as the actual   size of the whiteboard changes and then the start  method we're going to need to get the renderer so   var r is going to be let's spell that wrong var r  it's going to be equal to get component renderer   and then from the renderer we can grab the texture  we're going to create a new 2d texture and then   we're going to set this as the main texture  of the renderer so let's do a new texture 2d   and we're going to set this to int texture  size dot x and then int texture size   dot y i'm going to set that to the r dot material  dot main texture and that's all we need for the   whiteboard script so just set it getting the  resolution and setting that as a new texture so   that we can now manipulate it and then just make  sure that you add your script onto the whiteboard   and then we're actually going to tag whiteboard  as whiteboard just create a new whiteboard tag   just so that we can access this later  and do some you know do a little bit   more elegant kind of a debugging and whatnot  so we're going to tag this as whiteboard now   let's create a whiteboard marker script so new  c sharp script whiteboard marker open that one   up and this is where the meat and potatoes is so  first thing we need to do is get access to the tip   and then we also want to set a pen size and this  can be adjusted later so if you want to have a   slider or something that will you know make the  marker bigger or smaller when you're drawing then   you can use this variable for that so these are  going to be two serialized fields first one's   gonna be the transform of the tip and the second  one also serialize field is going to be just an   integer of a pin size and we're gonna set that  to five to start out with and then in order to   get the material color we need access to the  renderer so we're going to say private renderer   renderer and then from here we can  grab that renderer from git component   and that's going to give us access to the  color and right now when we are coloring in a   splotch of so like let's say i just dotted the  whiteboard we want to color in a decent amount   of pixels so right now we're just going to be  coloring in squares because that's the easiest   kind of algorithm to run so we're going to be  coloring in a 5 by 5 square of pixels in this case   we need a 25 length uh color array so we just  need 25 colors of whatever the render color is   so all 25 pixels in that little square that we  make need to be the same color so we just need   to create an array of you know the render color  so to do that we're going to create a color array   so private color this is just going to be colors  colors is going to be equal to enumerable and   we're going to repeat and basically this is  just you know taking one value and repeating   it over you know however large we want it  to be the value we want is the renderer   dot material.color and then how many times  we want is just pin size times pen size   and we're going to set this equal to an array  so if you wanted to do a circle or some other   shape of the pen you would want to calculate  how many pixels you actually needed to change   for that particular circle or whatever so that'd  be a little bit harder of a calculation but we're   going to stick with super easy geometry of just  length times width in this case and then one more   thing we need to do in the start method is to get  the length of the tip we're going to use this for   a raycast to see if we're actually touching the  whiteboard or not so we're going to create a new   private variable it's going to be a float and  we're just going to call it tip height and that   will just get set with tip height is going to  be equal to the tip dot local scale dot y and   that's all of our setup and then we want to every  frame check and say are we touching a white board   if we're touching a white board we want to  check and see what the resolution is and   do some of that and then we're going to  change the texture of that whiteboard   in the particular spot we're touching and then  we also want to do a little bit of interpolation   so just in case we're moving the pin really fast  it doesn't just like give us some dots it actually   streaks correctly and gives us an actual line  so a few different things we're gonna kind of   dive into that and we're gonna do this all in a  separate method i like to keep my update methods   quite simple so we're just going to say draw  and create a new method so every frame we're   going to call this draw method it's going to be  a private void draw first thing we want to do   is check and see if we're touching anything so we  need to do a raycast we're going to do this inside   of an if statement physics raycast we're going  to start at the tips position so tip.position   we want to be going up because the the way the  marker is oriented the y direction is up so that's   the direction the raycast needs to be going so  we're just going to say transform.up because we   are currently inside of the marker object so it's  transform we can use we want to get out a variable   of touch and this is going to be a raycast  hit let's create a new private raycast hit   variable and we want to raycast the length of  the tip height that we calculated earlier so if   we actually hit something within these  parameters starting from the position   going up and a length of the tip height  then we're going to jump into here and   then we will get out this touch raycast hit  variable and inside of here we want to see   does that touch object actually have the tag of  whiteboard so if we're touching the table we don't   actually want to mark on the table and this will  allow us to mark on specific things so inside of   here we're going to do another if statement is  going to say if the touch.transform.comparetag is whiteboard then we can continue on and do some  more things the first thing we want to do is cache   that whiteboard script that we made earlier so  we're going to say if and we're going to create   a new variable for whiteboard so if whiteboard  is null then we're going to say whiteboard   is equal to touch dot transform dot get component  white board so every everything with the tag of   whiteboard should also have the script of  whiteboard which will be convenient for us   so we're going to create a new  private variable whiteboard   and to checking to see if it is set or not will  allow us to only do it that first time you touch   and not every other frame afterwards because that  kind of creates a little bit of a draw on the   processing so we only want to do this the first  time and not every iteration afterwards while   you're creating the line next we want to grab the  touch position that we uh touch the white board   on so we're going to create a new variable called  touch pause and that's going to be equal to a new   vector 2 which has the touch dot texture  coordinate dot x and touch dot texture coordinate   dot y and let's create that touch two variable  touch pause now we're going to do a little math to   calculate where on the actual whiteboard  that we're touching in relation to the   resolution that we set up earlier so that 2048  resolution that we have by default this is   where in that 2048 pixels are we actually  touching so we're kind of doing a little   math to translate from the actual touch  position in unity in x and y to a pixel so   we're transferring it from a float number to a  pixel number of what pixel inside of the actual   screen or resolution we are actually touching so  we're going to say var x is going to be equal to   a forced int value of touch pause dot x multiply  that by the white board dot texture size   dot x and then we're gonna subtract the  pin size divided by two so we want the uh   basically we want to account for just in case the  uh pin kind of overwrites writes outside of the   texture we're only going up to that edge and then  i'm just going to press ctrl d with my cursor on   that line and i'll duplicate it for us and we can  change the x values to y and now we're gonna do   a out of bounds check so this just checks to  make sure if you're dragging your pen and you   drag it off of the whiteboard then it's going to  stop trying to draw the line anymore and we'll   actually just exit the loop here if we don't  have this line that i'm about to write it'll   give us an error in unity and unity it doesn't  doesn't like that so we're going to say if y   is less than 0 we don't need to account for the  pin size anymore because we did that in the x   and y pixel calculation so if a y is less than  0 or if y is greater than the whiteboard dot   texture size on the y axis or same thing for  x so i'm just going to highlight all of this   press ctrl d again that'll duplicate it for us add  another or statement in there and then change all   these y's to x's and then at the end of that  i want to return this will just drop us out of   this draw method if we are actually out of bounds  so if y ends up being a negative one or something   then you know we know we're not on the whiteboard  anymore so let's just leave and not try to draw   anymore now we can actually start drawing so  after all of these calculations and checks and   whatnot we can actually start drawing so we're  going to say if we have touched the last frame   which is going to be a new bool variable  that we have go up to the top and create that   private bool touch last frame then we actually  want to draw so we're going to say the set whiteboard.texture.setpixels and we want it to  be on the x and y coordinate and the block width   is going to be pen size and block height is also  going to be pen size and the color is going to   be that colors array that we made earlier so  this sets the point that we actually touch   but then we also kind of want to interpolate and  say okay well you know between last frame and this   frame we also want to color in all those points if  we were still touching and didn't pick up the pin   the easy part is coloring in every spot that  we touch the hard part is kind of interpolating   that and creating a nice line so to do that we  need a for loop and here you can kind of set   how many iterations so this is going to be like a  basically a percentage value so how much percent   coverage do you want so we can set um so we're  going to have a float so this is going to be a   not an int but a float of f f is going to be equal  to 0.01 i'm going to say if f is less than 1.00   then we're going to go through the loop and then  instead of adding 1 every time we're going to add   f is going to be plus equals 0.01 so we have a  float we're starting at zero one point zero one   so one percent and then we're going up to a  hundred percent and every frame or not every   frame is how it happens in one frame so be a  little careful if you're kind of having a little   latency you can increase this value  to increase by three and now you're   only having about 30 coverage in between instead  of 100 coverage in between so inside of here   we're just going to do a little interpolation so  var lerp x going to be equal to a forced int of   math f lerp last touched position which we'll  set later so at the very end we'll set last touch   position and the x value of that and then we want  to interpolate between the last touch position and   this current position and we will basically fill  that gap in i'm going to press ctrl d to duplicate   that and change all the x's to y's and then i'm  going to copy this whiteboard texture set pixels   paste that down below here and instead of x and  y we want the lerp x and y and that will fill   that in so let's go back and create this last  touch pause it's going to be a vector 2 as well   we can actually write it behind this touch pause  so last touch pause the touch or touched forgot   what i wrote yeah last touch so we're setting  the original point that we touch and then we're   looping through either you know one of a hundred  or three of a hundred depending on this number   to fill in the space between the last point  we touched and the current point we touched   and then we're setting that pixel as or set  setting that group of pixels as well and then   we also want to keep track of the last touched  rotation and we're going to set the last   rotation to the current rotation so basically  what we're doing is preventing so if i in   vr if i am you know using physics to  actually push my pin against this wall in vr   you don't have any like kind of movement grip like  this so your pin will just kind of flop like that   and so we basically want to lock the rotation when  we touch the whiteboard so your pin doesn't like   use physics and just go flat against the  whiteboard so we're going to lock the you   know whatever rotation you hit we're going to  lock it while you're touching and then when we   let go we'll release that rotation again so  basically just prevents us from going like that   when you push into the whiteboard because  you don't have that tactile like response   of touching the whiteboard so to do that we just  do transform.rotation is going to be equals to the   last touch we'll just do last touch rot rotation  and this is going to be a quaternion so private   quaternion is going to be equal is last touch and  then after all that we want to apply so we'll do   whiteboard.texture.apply and that will set all of  these pixels that we changed and actually update   the texture and then outside of the last touch  frame we want to actually set all of these values   from the last frame so that we have access to them  in the current frame so this is where we set the   last touch position that's going to be equal to a  new vector 2 of the x and y values we want to set   the last touch rotation it's going to be equal  to the transform dot rotation and then we want   to set last touch or touch last frame equal to  true and then we're actually going to return so   we're going to end the method here because instead  of writing if else this if else do the same thing   we're just going to add in at the very bottom here  so if you you didn't go through the if statements   didn't successfully go through all of them and  hit this return statement then you'll end up   be getting all the way down to the bottom here and  this is where we're going to unset the whiteboard   so whiteboard is going to be equal to null and  then we're going to unset the touch last frame   that's going to be equal to false so if we if our  pin isn't actually touching anything and if that   thing is not actually a whiteboard then instead of  ending up hitting this return statement we'll come   down and hit this line of code which will unset  the whiteboard and unset the touch last frame so   that we're not going through that over and over  again and this is all the code so i'll go through   it one more time just so you can kind of see  it and get any parts that you might have missed   so these are the variables that we have our start  method where we get the renderer set up the colors   array and the tip height in the update method  we're just calling this a draw method every frame   and then in the draw method we are doing a physics  raycast checking for a whiteboard if the item   we're touching is a whiteboard if we have cached  the whiteboard object already we're going to skip   otherwise we're going to get component and since  git component like takes a little bit longer   we don't want to be doing this every frame so we  have this little cache kind of if statement here   we're going to grab the touch position from  our texture coordinates we're going to convert   that touch position to the whiteboard's texture  size or basically converting the touch position   to the specific x and y pixels that we're  touching we're going to say if those pixels   are actually outside of the texture we want  to exit and we don't want to continue to draw   and then we're going to check and see okay if we  touch the last frame then we want to go ahead and   color in some pixels but if we didn't touch the  last frame we want to set the last frame items   and so the way this works is we don't actually  ever color the first time we touch the screen   but the second frame we will have already  touched and it's going to interpolate that first   spot to the next spot so we actually do get all  of those pixels colored in correctly it's just   essentially happening one happening one frame  late so we are setting the initial point that   we touched the the initial pixel or group of  pixels and then we are interpolating from the   last point that we touch to the current and then  we are essentially locking the rotation so your   pen doesn't snap up to uh be in line with the  whiteboard which is really annoying and then we   are actually applying the coloration to the pixels  and then we're setting all the caching for the   next frame so we have access to it and then if we  didn't go through all of those then we're going to   uncache the whiteboard and set touch last frame  equal to false so i'm going to save that go back   into unity and then the marker we need to make  sure that our whiteboard marker script is on the   marker it's on the uh the parent object and then  make sure you set the tip and set the pen size our   whiteboard has the web board script on it and is  tagged with whiteboard and then the texture size   so the x and y axis the i think the y-axis in this  particular case is the x-axis so you have to kind   of play around with the texture size and so in  this case since our transform scale is one to   three so we're going to say this 2048 is one and  then this 2048 we're gonna multiply by three hit   enter and that'll update our texture size for us  and so now we'll get a nice even square instead of   kind of a oblong rectangle drawing shape and now  we haven't set up vr yet we're going to test it   so i'm going to hit play wait for that to go  we're going to go back into scene view and then   i'm going to grab the marker make sure you're  grabbing the the parent object of the marker   and oh so we missed one thing and i know we missed  one more thing so there is no render attached to   marker we actually instead of grabbing the in  the start method when we grab this git component   renderer we actually want to get component of the  tip tip dot git component and that'll get whatever   the color the tip is so now that was the mistake  just add in tip dot to that that'll fix that and   then then i think we're good one more thing that's  worth noting though is the whatever object you are   turning into the whiteboard so if you do end up  using a cube or something like that make sure you   have a mesh collider on it and not a box collider  or a sphere collider or something like that has   to be a mesh collider in order for this kind of  texture um drawing to work so i'm going to save   all this again hit play we're going to see if  this one works all right no errors that's good   go back into our scene view grab the marker and we  are drawing and it is quite small in comparison to   the actual marker so we could um let's up the  pen size a little bit here oh let's uh pause it   and then up the pen size let's let's go let's do  15. see how that looks so it's really just kind   of getting the scale of the marker in line with  whatever your pin size is so now now the pin size   a little bit bigger we could move the uh we could  size down the marker a little bit if we wanted to   so now i'm getting close and if you move very  fast you should so you'll see this is our   interpolation so basically we had one point here  and one point here and it kind of interpolated   and just made a whole bunch of little dots here  so if you wanted to increase that interpolation   you could you know make it an even smaller  increment but that also kind of decreases your   processing a little bit so as long as it's a  relatively smooth line you should be fine and   just make sure that when you disconnect from the  board and then reconnect you don't have like a   line that draws across and tries to connect to  the those two lines as well so there we go we   have our our little white board and now we can set  it up for vr and this will work for any kind of vr   whether you're using a tool kit that you  imported from the asset store which you know   hurricane autohand all of those those all work  with this also the uh you know xr interaction   system that we're about to set up i'll show  you how to set that up with this particular   case just so you you can have a full video of it  even includes you know how to set up the xr for   this particular part so if you already have set  up xr you can probably skip you can probably in   the video now because i'm basically just gonna  add this to velocity tracking and uh setup xr   so let's uh let's set this up and uh just a  reminder the code is in my patreon if you don't   feel like writing all of it i know it's a little  confusing or if you end up running into some bugs   feel free to join the patreon which is also linked  in the description it is a free resource and super   helpful we have a very active dev help channel  and a lot of good admins and moderators who are   really helpful and really knowledgeable about vr  development so join the discord if you have not   already it's been a minute since i've shouted that  out so let's set up xr for this particular project   so we're going to want to go to project settings  scroll all the way down to xr plugin management   and install that once that's installed we'll get  a list of check boxes here we're going to check   open xr that'll install some more things it's  going to ask us to restart unity and it's going to   update the input system from the old input system  to the new input system so just hit yes it'll   restart unity there we go once unity is restarted  you'll see this little exclamation point triangle   want to fix the item that it lets you fix and then  click on edit that'll take you to the open xr page   so from xr plugin management open xr and it wants  you to add in at least one interaction profile so   i'm using oculus touch and then i also use valve  index so i'll add both of those in there because   why not and then we want to add in the unity  preview package so we need to go up to package   manager and click enable pre-release packages and  say i understand that these are in pre-release and   then go over to the package manager both project  settings and package manager can be accessed from   this window bar up here project settings is edit  project settings and package manager is window   package manager and then inside package manager  we want to swap from in project packages to   unity registry packages scroll all the way  down to the xr interaction toolkit preview   install that one and there is a default input  action sample that we want to download as well   so import that one as well and that will give us a  samples folder with some default input actions if   we click on those it gives us some presets that we  can add so we want to add let's do continuous move   we're going to add the left controller the  right controller and snap turn so this basically   pre-sets up some input actions so we don't have  to go through and do it manually it's quite nice   let's go back into our scene view now actually one  more thing before that project settings and preset   manager and then now so these are all the presets  that we added by clicking on this button here at   the top on the left and right hand controllers we  just need to add right and left to the appropriate   filter for that particular input action and this  just helps further set up that's the only thing   you have to actually type in to help life with  the setup it's a little finicky and weird but   so now we need to add in an xr rig into our  system so we can right click go to xr and   xr rig action based click on that that'll add in  the xr rig i'm going to reset it to the center if   you don't see the green box make sure your gizmos  is turned on and then i can rotate that so the   x-axis is pointing forward towards the whiteboard  that we actually want to interact with and then if   you want to add in some movement we're going to  right click go to xr and the locomotion system   and then we're going to add in we're going to  remove the teleportation and add in snap well   snap turns already in there we're going to add  in continuous move make sure it's action based   and then we want to set up make sure the hands are  correct so for snap turn we want to use the right   hand to do snap turn so i'm going to uncheck  the left hand and then for continuous move we   want to use the left hand thumbstick for that  so i'm going to uncheck the right hand and now   that is all set up we can drag and drop the xr rig  it'll automatically find it if you don't do that   that just helps me for peace of mind and then  let's see there's a few more things we need to   add in so the left hand controller make sure  that all of these references are left hand   same for the right hand to make sure they're  all right hand and you don't have one that has   just left hit like both of them have left hand  interactions or something like that that would   mean that you didn't actually set up the filter if  you didn't actually type in the filter correctly   um there's one setting i always like to  uncheck and that is anchor control on the   left hand and right hand controllers and that  basically means while i'm using the thumbsticks   if i'm holding something it's going to move that  something that i'm holding with the thumbstick and   i don't know why that's checked by default it's  super annoying so i always uncheck it and then   if we want to be able to you can also adjust the  xr line visual here as well and then we want to   be able to grab the marker so on the marker i'm  going to add a component we're going to add a grab   interactable that's going to automatically  add a rigid body that you can adjust to use   gravity and whatnot and then inside of the xr  grab interactable we want to swap the movement   type instantaneous will let us just go through  the whiteboard as well as kinematic 2 i believe   but if we do velocity tracking it will actually  connect with the whiteboard and the object the   marker won't actually go through the whiteboard  and that's why we set up the rotation freeze when   you touch the whiteboard so your whiteboard so  your marker doesn't like snap to the whiteboard   when you press up against it so now everything  is set up if you want to you could create some   prefabs so we can create a prefabs folder inside  of the whiteboard folder and then i can drag and   drop my whiteboard in there and the marker in  there and now let me save this make sure i'm in   link mode and then hit play and we'll see what  we have we go so we have our whiteboard oh one   more thing i missed i always forget this on the xr  interaction manager let's add in the input action   manager component and then we want to drag and  drop this default input actions onto the action   assets i always forget this component so you have  to add this in in order for your controllers to   actually move when you uh are in the scene so  that was it that was the only thing i missed   hit play again and now where's the marker oh let's  uh uncheck use gravity for the marker so i don't   lose it so marker rigid body uncheck use  gravity and oh and then also we set up the   grab point for the marker so inside of our  grab interactable we can set that as well so   under attach transform let's throw that grab point  there there we go and then make sure to apply that   to your prefab as well so it saves there hit play  again and our marker shouldn't disappear on us   there we go so grab the marker it is quite  large so now when i go on the whiteboard   i can color correctly ta-da and it doesn't  use gravity so bye-bye oh can i just like   throw it and have it because the position  freezes that that's interesting anyway   well there you go that's how you set up a marker  to use in vr to uh set up a little whiteboard i   will probably do a eraser kind of video later  and it's going to be mostly the exact same but   we're just going to reference the render color  of the whiteboard and just use that as our   drawing so it'll basically just be drawing on  whatever the original color of the whiteboard   is back wherever the eraser is so that's  that's how you do an eraser if you want to   set that up as well and then to change the color  of the marker all you have to do is change the   material because we're referencing the materials  so that's pretty handy so you can have multiple   markers and multiple whiteboards and all that kind  of stuff so have fun i would love to hear from you   in the comments if this worked for you if it does  not work for you join the discord and we can help   you out in the dev help page and as always all the  code is available on my patreon the whole project   and everything if you're really running into  bugs or you don't want to type everything out   and whatnot so look forward to seeing you  again soon and uh i'll see you in the next one you
Info
Channel: Justin P Barnett - VR Game Dev
Views: 4,625
Rating: undefined out of 5
Keywords: unity xr, unity new input system, xr interaction toolkit, unity vr tutorial, unity xr toolkit, xr toolkit, oculus quest 2, unity tutorial, unity vr development, vr tutorial beginner, whiteboard tutorial, vr whiteboard, vr whiteboard tutorial, how to make a virtual reality game in unity, vr development, vr tutorial unity, xr unity tutorial, unity xr toolkit tutorial, unity xr interaction toolkit, vr, xr toolkit unity, unity openxr, openxr, xr interaction toolkit unity, vr ux
Id: sHE5ubsP-E8
Channel Id: undefined
Length: 38min 40sec (2320 seconds)
Published: Wed Nov 17 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.