Introduction to VR in Unity - PART 8 : SNAP ZONE
ฝัง
- เผยแพร่เมื่อ 5 ก.ย. 2024
- In this video, I will show you how to help you player interact with your world with drop zone that snap the interactable to a predefined position and triggers custom behavior.
❤️ Support on Patreon : / valemvr
🔔 Subscribe : www.youtube.co...
🌍 Discord : / discord
🐦Twitter : va...
🔥 Tiktok : / valemxr
👍 Learn VR Development : www.youtube.co...
NEXT EPISODE : • Introduction to VR in ...
PREVIOUS EPISODE : • Introduction to VR in ...
····················································································
📝Best VR Assets ( These links are Affiliate links which means it costs the same to you and I get a small commission. Thanks for your support!)
VR Interaction Framework
assetstore.uni...
Hexabody (Physics VR Player)
assetstore.uni...
Mirror and Reflection for VR
assetstore.uni...
Auto Hand (automatic hand grab pose)
assetstore.uni...
Hurricane VR (vr physics interaction)
assetstore.uni...
3d Hand Model for VR
assetstore.uni...
····················································································
Full Series on How to make a VR game • How to Make a VR Game ...
····················································································
If you want to learn VR dev, here are some other really good channel you should appreciate :
⌨️ Game Dev
Brackeys : / @brackeys
Dani : / @danidev
Code Monkey : / @codemonkeyunity
👨🎓 Vr Dev
Valem Tutorials : / @valemtutorials
Justin P Barnett : / @justinpbarnett
Vr with Andrew : / @vrwithandrew
····················································································
#vr #vrdev #madewithunity #valem #unity
Hey guys ! I made an update of this series on my channel Valem tutorial that you can find here : th-cam.com/video/fM0k2n7u8sc/w-d-xo.html
You are always suprising me offering the exact tutorial I am looking for
Ikr, I literally needed this yesterday, lol.
This is what I've been waiting for!
Thanks Valem 😁
this is great! how about some enemies next? would like to know how to physically interact with another character with that lightsabre?
Thank you so much! This helped me with my holsters, I love how it is extremely simple and intuitive.
Another excellent tutorial! And it is funny... I was about to work on creating drop zones for attaching swords and potions to a belt, but you saved me a bunch of time. Thanks again :)
Yay! I really like this series! Thanks for another episode
I love this series
You are very skilled. Great tutorial! Thank you for bringing this to the masses! 😁
i realy like how motivated you are in every video :D
It wasn't entirely clear to me what the follow math was doing, but to me, if you want something which basically follows your position and direction you are facing, and offsets but only taking into account Y rotation, I'd do something like:
transform.rotation = Quaternion.Euler(0f, target.transform.rotation.eulerAngles.y, 0f);
Matrix4x4 m = Matrix4x4.TRS(target.transform.position, transform.rotation, target.transform.localScale);
transform.position = m.MultiplyPoint(offset);
This seemed to work for me (it gave me inventory slots which were always below my head, around my waist, on the left and right.
Valem: only uses box colliders and sphere colliders
Mesh Collider: Am i a joke to you?
The Mesh Collider is more accurate when it comes to establishing collisions, but on the other hand it can give problems and inaccuracies when Unity has to calculate its physics. Whenever you can, use a box collider.
@@PhantomWolf93 I feel like whenever I have a problem with collisions being detected it is because I'm using a mesh collider, way less problems with the other types. Idk what the problem is.
A Convex Mesh Collider Will Work Though
how TF did you not get 1M view?, this tutorial is very good and explained really well.
thank you for this high-quality info
Thanks again for the tutorials. I would love to learn how to make the snapzones not scoop up items I pass by. I only want items I place in them via hover to get grabbed. I've tried some solutions with no success yet.
Thanks valem! :)
Great videos! It would be great if you could make a video showing how to replace the hands in steamVR into custom ones, there is very little information on how to do this and seems quite difficult!
Can you do a video like "how to make a body in VR" but with Unity XR now?
its the exact same
Lol, I had a cool bug where the door and drawer from the previous tutorial are grabbables, and so when I opened the drawer it would collide with the inventory dropzone that was following me around and completely break the physics!
Did you fix it? I have the same problem.
Dani *uses your tutorial*
his subscribers *SUBS TO VALEM OUR AMAZING VR LORD*
This is awesome!!
keep up the good work ! thx for the tutorial series 👍🙂🙂
Woudnt you be able to put anithing 9n your head is there a way to make it so you kan only put things on your head with a specific tag
A bit late, but for anyone still looking for this. Check out his second tutorial on creating a realistic gun, there he gives a script to extend the socket interactor with a tag.
@@charlottedegooijer4536 Thank you!
Gracias c: tus videos son de mucha ayuda.
Hey Valem, thank you for all of the work you've done on this series. I used to make GearVR games, and took a few years off. Now getting into Quest development with the help of your tutorials.
I was wondering if we could see how to make functions that respond to the Touch Triggers being held down. Like a gun that charges while held down, and shoots on release. It doesn't seem like there is any equivalent to "GetButtonDown(0)" for the touch controllers.
Thanks again!
Yeah I wish you could just do something like "Input.GetAxis("LeftTouchControllerTrigger");"
I just had to make my own input manager and get the variables that has for each input from other scripts.
Another mind-blow! Haha!
Next tutorial idea how to make a sword attack an enemy or something like that
That's just normal unity stuff, nothing specific to VR really. Except for that you're experiencing it in VR. Just take a collider and when it touches the enemy make the health go down.
That's great, nice tutorial!
Hey Valem really enjoy your tutorial. One question considering Socket Snap Zones in XR. Is there a way that I restrict my snapping zone? So my Gun has a specific Snap zone that no other object can snap to. E.G. via a Tag. So only a Gun with a "Gun Tag" and the Snap zone with the Tag "Gun Snap" can work/snap togehter? Would be nice to have this additional info.
A year late but in the xr socket interactor theres a tab that says interaction layer mask, set it to the layer u want and only objects within that layer can snap into it.
How about a tutorial on how to make an object grabable with both hands at once?
this is what i need. i have already tested it with the OVR stuff i have a working two hand rifle. but i just dont know how to use two hand holds with the XR toolkit.
@@adhochero6619 Hey, I just found exactly what you were looking for. There are three videos that can help you out with doing two handed weapons / objects. Check them out! Here's the link on the first video, I hope it will help
th-cam.com/video/IX2EUAcocoM/w-d-xo.html
He made one :) Part 10 ;] th-cam.com/video/Ie0-oKN3Lq0/w-d-xo.html
Keep it up 😛😇
This is great! I always check my feed for when you release new videos! Is there a way to connect this snap zone functionality to a trigger? Say, inserting a card to open a door?
Thank you for this excellent tutorial series! I'd like to report a bug that I found with XR Interaction Toolkit with URP on oculus go. Same issue might be with quest? XR Socket interactable is not working when project is using URP. Could you test this project on quest and see if the same bug remains?
Found the bug in XRSocketInteractor script on material creation on lines 74-88. After replacing the lines 74-88 with below code, the snap zones work on Oculus Go (possible issue on Quest too?):
if (m_InteractableHoverMeshMaterial == null)
{
// create of default transparent shader
var m_InteractableHoverMeshMaterial = new Material(Shader.Find("Universal Render Pipeline/Lit"));
if (m_InteractableHoverMeshMaterial)
{
/* m_InteractableHoverMeshMaterial.SetFloat("_Mode", 2);
m_InteractableHoverMeshMaterial.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
m_InteractableHoverMeshMaterial.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
m_InteractableHoverMeshMaterial.SetInt("_ZWrite", 0);
m_InteractableHoverMeshMaterial.DisableKeyword("_ALPHATEST_ON");
m_InteractableHoverMeshMaterial.EnableKeyword("_ALPHABLEND_ON");
m_InteractableHoverMeshMaterial.DisableKeyword("_ALPHAPREMULTIPLY_ON");
*/
m_InteractableHoverMeshMaterial.SetColor("_Color", new Color(0.0f, 0.0f, 1.0f, 0.6f));
}
@@silwerifpv8395 yes this is an issue on quest if you run the game it just not there no sockets whatsoever
@@silwerifpv8395 Thank you so much, this fixed the issue with XR Socket Interactable not working with URP :)
I also found this issue on Oculus Quest. Thanks a ton for finding the bug and the fix! I was about to remove URP from my project but with this fix I will continue with URP!
Also I am not sure if we need to comment out those m_InteractableHoverMeshMaterial setters (between /* and */). I left them in, only changed var m_InteractableHoverMeshMaterial = new Material(Shader.Find("Standard")); => var m_InteractableHoverMeshMaterial = new Material(Shader.Find("Universal Render Pipeline/Lit"));. Apparently Unity team forgot to change this line of code (still trying to find Standard shader). With this one line code change Socket Interactor works as expected on Oculus quest.
@@silwerifpv8395 Thanks for finding this fix, dude!
Can you teach climbing next? Great vid btw!
THANKS! :D
Nice thank you for the tutorial c:
Hey I'm having a bit of an issue. On your code when i walk by the draws the the draw and door get sucked up into the inventory slots. I have tried making a couple of changes but seem to make it all work or all break :D Is there anyway to set it so only certain layers can use the inventory or the object has to be held in the hand and dropped before being added to the drop zone?
Did you manage to solve it? I'm using the Interaction Layer mask to do it but you have to do it on every grabbable item
@@rikusoulz I some what just got around it. From memory I put the inventory areas into a new layer and allowed them to interact with standard grab items but not the doors, draws, levers, etc. It worked for what I wanted and it meant nothing else needed changing.
How do you make it so only one specific object can be put into a drop zone? Like with the hat, you could put anything on your head. I wanma make a key system but I dont want a gun in there. I guess I could just use a function that checks if its that exact object, but you will be able to put anything in there.
I guess you can just play with the layers. Look at the "XR Socket Interactor" component of your DropZone. You can chose the layer it is interacting with.
Okay I just did it. Follow my steps. Lets say I want to make a holster for my Lightsaber. And the light saber will be the only thing I can attach to it.
1) Create a dropzone like in the video.
2) Create a layer called "Light Saber Holster".
3) In the "XR Sockets Interactor" component of your dropzone, there is a line called "Interaction Layer Mask" wich is set to "everything". Put it to "Light Saber Holster" only.
4) Now look at your Light Saber. It has a component called "XR Grab Interactable". There is the same parameter called "Interaction Layer Mask". It is set to "everything". You will notice you can attach your LightSaber to your Holster just like that. But, we dont want any other object to be able to attach to that holster. Here is the trick. You have to change the "interaction layer mask" of every other object to uncheck the layer "Light Saber Holster" that we created.
It is a bit long, but in the end its very effective. Because you dont have to change the layer of any of your objects, just the layer mask. If not, you wouldnt be able to grab them anymore. Tell me if you have a problem.
@@Mtech7752 I'm trying the route of a custom function so I can just check the tag of the object being held in the snap zone, but I can't get it to work, it just says NOT A FOX everytime even if it IS tagged as "fox":
public void IsItAFox(Collider other)
{
if (other.tag == "fox")
{
Debug.Log("Yes, it's a fox hovering");
}
else
{
Debug.Log("NOT A FOX HOVERING");
}
@@Mtech7752 hey just found this comment 2 years later. I appreciate you going through and doing it (youtube never gave me a notifcation so i never knew! haha) but thank you for going through the effort, it is much appreciated.
Hi this tutorial is great and everything working when testing in unity though the link. but when i build and run it to my quest headset, the socket stuff is just gone it no visible socket zone on hover no predetermined object in the slot nothing. has anyone else had this problem. everything else works, even the climbing, just not the sockets.
I have the same problem. Did you find a way to fix this?
Is the XR Socket Interactor broken in Unity 2019.4.1f1? Mine is not grabbing anything i put in the sphere, it just falls through. I have a sphere collider set to trigger and added the XRSocket interactor but it's not working. (FIXED) read SilweriFPV comment here, has a fix for the XR Socket Interactable not working with URP. I just tested it and now works on the Quest.
Hello, Valem thanks for this amazing series! I have one question maybe you know by any chance how to programmatically force interactor (hand) to put some interactable (let say ligthsaber) in hand and then also programmatically remove it from hand (direct interactor)?
do you have a video for OVR and oculus quest 2 not using XR interaction toolkit
Merci pour tes vidéos que je découvre en ce moment, dommage qu'elles ne soit pas en français 😉 signé : un camarade de Bxl ✌🔥!!!
Valem I have a problem - When I use the socket interactor with an object that has the offset interactable instead of the standard one, the attach transform doesn't work. Is there any workaround for this? Thank you in advance if you reply.
I am having the same issue, it grabs the object but won’t let me set the location
Same issue here. Did you ever figure out how to use an offset grab with the socket?
Can you plz make a video about locks and keys and maybe number padlocks?
Do you have any experience with unreal engine? If you do can you make a series on it?
Great Tutorial. Can you snap multiple objects to the one point if they are different heights?
Is there any easy way to resize the object inside the socket without having to extend the XR Socket Interactor? I tried to resize the "Attach Transform" scale, but it didnt work. Looks like the attach transform is used only to get the position and rotation. Thanks in advance! Valem your videos videos are awesome!
Thx
Very nice job!
Just one question, just noticed that if I have the two inventorys (left and right) when I continuous turn, I see like with less fps and is not fluent, not SMOOTH and If I disable the two inventorys changes and has a smooth turning move. Any way to solve this? I really want to have inventory and a normal turn, not stuttered and the only hint I have investigating is that is caused by the "Follow To The Side" script, that causes the turn to be less smooth
Yay!
Please someone help me! I can drop object in mu dropzone, but I can't take them out of the dropzone. Can somebody help me?
hi Tim, do you have an error showing in the console ? :)
Valem Hi! No, I don’t have an error. It’s like when the object (Unity cube) is in the drop zone (sphere), it seems like they just don’t collide. I’ve done just as you did in your video. I’ve checked the collission matrix, but there is everything is normal there
@@TimT26 have you checked is trigger on the sphere collider? As in the drop zone collider?
@@TimT26 have you fixed it ? I have the same problem
ive spent about two hours trying to replicate this and I cant actually get anything to snap into the socket or even seem to register a collision
Imagine making an inventory out of this
Is anyone else getting an InvalidOperationException: Collection was modified; enumeration operation may not execute error whenever they put something inside of an XR Socket Interactor?
Hey I was just wondering if there was a better way to track grabbed objects as I like the physics collisions of the velocity tracked movement type but I don't like the jittering when moving whit continuous. Is there a better way of doing it?
What i have to do to add in the "FollowToTheSide" Script, that i can adjust the rotation of the Drop Zone?
Would it not make it easier to child the obj to the head with the offset?
Hey is it possible to make the dropzone look like the object which needs to be grabbed?
any idea how to do it with the standard oculus integration?
Hey valem, maybe you know the TH-camr Dani (he has 1 mill subs) and he used your tutorial lol
hey, do you know how to make a working spin the wheel in vr?
Why is my snapzone can sometimes put the things in, sometimes not??
Can I apply this in 3d not vr?
How to make sound when the controller hits any object ? Can any one help me please ?
Hi . I follow all steps but still the snap not working for me
Regarding the script for the movement of inventory slots with the character. If u want it to follow in the same manner as "CapsuleFollowHeadset" from previous tutorial, replace the FixedUpdate with this:
void FixedUpdate()
{
transform.position = characterTransform.TransformPoint(character.center);
transform.eulerAngles = new Vector3(0, VRCamera.eulerAngles.y, 0);
}
i did not include the offset because I just need this for inventory slots around the belt of the player, for me orienting the gameobject is enough since I track the height.
I placed three sphere objects with the socket component under an empty game object that has the script with the code above. Hope it helps.
Btw, if anyone knows how to make the whole character not go through walls please let me know, the code from the tutorial series did not work for me.
I am just gonna say this You should do udemy course with the latest content and a project within it that'd be great
If this works and don’t waste 20 minutes of my time you a big saver❤
so whathappened ? :D
@@ValemVR idk lol
The socket interactor doesn't work when you build the game ):
Can u make VR android with controller? Not use oculus but other controller??
My object enters the ball but when I want to take it out it stays there it does not connect to me at all does anyone know what the reason is?
I was searching for this comment cuz i have the same problem. Any solutions ?
where can i find these assets?
the objects fly away
Are you french ?
Am I able to sell a game with your source code
None of these tutorials don’t work for me
Is Unity paying you? Unity should pay you.
why