[07] VR for Beginners using Unity (Extras)
Вставка
- Опубліковано 11 вер 2024
- Support my work, and get access to source code! - / vrwithandrew
Finally let's create some extra functionality. Let's create a target, and score output for our projectile launcher.
Create a Target 0:25
Create a Text Mesh 2:48
Add Recoil to Weapon Script 4:20
- Apply Force to Weapon on Fire
Target Script 6:10
- Create a new class that inherit Unity event
- Make it serializable so it is visible in Unity Editor
- Emit UnityEvent on Hit
Score Script 11:30
- hold reference to TextMesh and update it
Create and assign Projectile tag 12:40
Communicate Score by Event 13:13
Continuous Collision Detection 14:15
====
Thank you! Picked up couples of things via your series. Looking forward to your future video!
well it took 3 tries over the course of 1 and a half years but I finally figured out the basics of VR game development. Thank you for making this outstanding tutorial series
You're welcome, Dimensional! I do what I can. :)
Seriously amazing course and so informative. Went from 0 to creating a game in a few hours today.
I do what I can! :)
Fun story for you. I've been doing VR Development for almost 10 days now (professional developer for many years). So I've been doing the tutorial circuit. I ended up with a VR rig that can grab things, turn and move. In my last tutorial, we added hands and animated them. Yea, I could grab the white block on the white "table" on the white ground. So I decided to stop there and spruce it up a bit. End up with a prefab table holding a red, green and blue block. Then I very quickly had a table next to it with 3 different colored spheres. Cool. So I added a third table and a low poly car model from the asset store. Then some more videos and learning. Then I had three cars, scaled down I could play with. By the end, I had another table with a male and female character, a table with food, and finally, a table with weapons. Including a handgun and assault rifle that were already lining up perfectly with my controllers.
Then I came across this series of videos. You had a gun. I had two. Why not? It took a while to get it working. I had it super close, then gave up. Then some more ideas, then gave up. A few rounds later, I discovered (watching one of your Half-Life videos), that I'd not setup the Activate function in the XR Grab Interactable on either of my weapons. Once I got that wired up, I ended up with a handgun and assault rifle that both shot, hit the target and showed scores. It can also shoot cubes, spheres, cars, characters, food and other miscellaneous weapons. :)
Finally, thanks to watching you set the transform on the gun when it's grabbed, my male and female characters now face the right way when I grab them.
Well, you got it working! Happy to be of assistance, Mark. :)
Haven't watched the video yet...just wanted to say a quick message before I do. Thank you very very much Andrew for some of the most informative VR development videos out there. You have truly been a huge help to me & am really glad I've found your channel. Looking forward to more videos! Thanks again legend.
Thank you, Ryzer! I really appreciate it.
Thank you so much for this course. After being hesitant in trying to work with VR in Unity (as I found many previous tutorials confusing), this was the perfect level of explanation for me.
You're quite welcome, Stuart! Glad to help!
I noticed that if you hit at the edge of a scoring ring it would be off on the values. Looking into it I found a better way of getting the impact point. Changing the position that you pass into the FigureOutScore from the projectile's center to the point of impact.
FigureOutScore(collision.transform.position)
Changes to
FigureOutScore(collision.GetContact(0).point)
dude thanks alot of for these really helped me learn some basics with scripts and stuff :D
Happy to help! :)
Is there anyway we can add Oculus app ID and Androidmanifest.xml? Otherwise if we make games with XR we can't submit the app on Oculus store. And OpenVR still in beta mode.
Unity technically takes care of the manifest for you, but you can easily import the VR/Platform folders from the Oculus Integration package for the needed tools.
Thank you for the helpfull tutorial!
Happy to help!
Hey. I set the LaunchProjectile to 100. I can hit the target, but i cant hit a sphere if its near. How can i fix that?
hello! Great tutorial! Is there a way to have the text follow the object around like an item tag? I saw vrtk allows you to do it, but I tried working with it and it seems that vrtk doesn't work with the current steamvr
You could do your own implementation. You'd just need some 3D text, child it to the interactable. Then have some look at functionality for it to look at the camera. That's a very basic implementation, so it probably needs some additional code.
@@VRwithAndrew ok thank you so much. I’ll look into figuring out how to shut it off. I got it hovering, just not turning off yet
very good
I have successfully developed the game, the video is very helpful
@@2imPhong Happy to help!
Video is great and very helpful, thank you! Have you noticed any delay in the projectile instantiation position when moving the hand holding the weapon? Or combining with a locomotion system such as continuous turn/move provider? In my project there is a seriously noticeable gap between the instantiated projectile prefab and the weapons position when moving the player/xr rig or weapon. Reproduceable on action-based & device-based... any thoughts?
Yeah, the continuous move doesn't properly take into account Kinematic or Velocity tracked movement properly. However, the instantiation position should be correct in relation to the weapon itself. If not, that would actually be pretty strange.
@@VRwithAndrew Yes I did notice if you set interpolate on the rigidbody of the grabbable object the tracking while moving is somewhat smoother. However it is the instantiation position that is faulty for me. forum.unity.com/threads/prefab-generated-from-position-of-xr-grab-interactable-lag-delay.1030924/
Disregard, the issue with the particle system was a combination of simulation space, scalling mode & culling mode. Also increasing the launchForce of the projectile helps as well.
Hey Andrew been watching your tutorials and adding new things i was wondering if you could me with making the hands not be ghost hands and collide with things if not i understand Thanks
Hey Zenz! I'm actually working on a non-intrusive way of doing that without have to create a custom controller.
great! Thx for the series!! The recoil doesnt work very good, is it?
It's certainly not the best thing around, but it gets the job done.
Hello Andrew,
First of all, I would like to thank you for all your amazing efforts.
I have a question regarding the target and the CollisionOnEnter function, I have applied it with the arrow and bow .. and when the arrow collided with the target, noting happen as the function is not working with me as I used to print a text within it and it didn’t printed out.. Can you or anyone here know how I can fix this issue?!
Thank you in advance
It could be a few things! Ensure that either the arrow or hit object has a rigidbody attached. Most likely, the arrow is moving too quickly and passes through the collider before a collision can occur. This is common with very fast-moving objects. I managed to get around this by firing a raycast from the arrow's previous position to its new position in the next frame.
@@VRwithAndrew thank you your reply Androw, for the arrow it is stopped at the target. If I will go with using the raycast, does there a way I can know if the hit was with the target because based on that I would like to adjust the score.
@@sasa-tr3hc In my updated Bow and Arrow video, I have an example on how to do this. A straightforward way is to check if the object that the the raycast hit has a component, then call a function on it.
@@VRwithAndrew thank you so much
Really enjoying the tutorials, but I'm having a bit of trouble adapting this to my own project. I'm building an archery game, so am taking aspects from the earlier bow and arrow tutorial and from this one. I've set up the arrow to fire an event when it hits an object which passes the RaycastHit to the Score script. The Score script and game object are exactly the same as you have here, but when I run it and I hit a target it throws an error saying "the variable textMesh of Score has not been assigned". The function itself works as when I just do a basic print() to show the RaycastHit info on screen it works fine. I've been over this tutorial several times and I can't see what I'm missing! Anyone got any ideas?
Do you know if you're using the old TextMesh or TextMeshPro? It may be easier for you to make the TestMesh variable public, and drop in a reference to it in the Inspector.
@@VRwithAndrew Thanks for responding. I was using the old TextMesh one, just to get something on screen for now (early days in my project so far!). I think I tried making the variable public and referencing it in the inspector and that didn't work properly either. I'll try again to see what I can come up with! :)
@@VRwithAndrew Hmmm... I tried referencing the TextMesh directly with a public variable and that stopped the error, but it doesn't appear to be updating the text while in game. The function is definitely running as I still have the print() statement which is showing in the console, but the text in the textmesh doesn't appear while in game. As soon as I exit game mode, though, it shows the text for the last object hit in the textmesh.
Other than the TextMesh issue, though, I'm fairly happy with how it's going so far. ua-cam.com/video/d10EvTKuI1c/v-deo.html
Looks great! You may want to check if you're not passing in an empty string to the textmesh. That's the only thing I can think of.