Realistic Gun in VR - Part 3
Vložit
- čas přidán 30. 10. 2020
- How to pull the slider to reload a gun!
Learn in this video how to make realistic fire weapon in Unity using the XR Interaction Toolkit.
▶ Get access to the source code: / valemvr
▶ Join the Discord channel: / discord
Download the Gun Sounds and the XROffset Grab Script :
drive.google.com/drive/folder... - Hry
Many many thanks for this video, Valem. It's been a massive help for creating my own vr weapon framework, expanding upon your methods here and building things a slightly different way. I've expanded it to allow manually ejecting bullets by pulling the handle back repeatedly while a mag is in and checking if the gun is already cocked before spitting a case and removing a round from the magazine.
You're seriously paving the way for so many vr developers! Thank you so much and keep them coming! 👌🏽
True! Without his tutorials I'd have never even started with my Cactus Cowboy VR games. Cannot thank him enough for those.
@@CactusVRstudios Oooooh Cactus Cowboy VR!!! my favorite game
@@magma5267 It's true. Lots of my gun mechanics are based on this video. Even the current in development title
@@CactusVRstudios Nice i loved the applab game i cant wait to play this new one
for anyone with problems with the gun moving around alone in the table, it is because of a glitch were the hitbox of the slider is bigger than the hitbox of the weapon itself, so to fix this just make the hitbox of the slider smaller
Can you make a 4th part explaining on how to add recoil? Thanks.
The "XROffsetGrabInteractable" script needs updated, unity changed OnSelectEnter
it is now either "OnSelectEntering" or "OnSelectEntered" same goes for OnSelectExit, though that's not used in the script.
ran into this problem doing this tutorial figured it may help someone!
still got a few errors ='(
thank you!
thanks for the help!
Thank you
Thank you so much for pointing this out!
I just made the gun! The last thing missing for my game is a knife/sword that does not suck. In other words, a sword that, when you e.g. stabs it through a box, causes it to get stuck and can only be pulled out again of a certain axis. That would be really cool. Thanks
This 3 part gun series is still great!
Cette chaîne est excellente. On ne trouve pas énormément de tuto VR aujourd'hui. Pouce bleu as usual ;)
Hey Valem, once again an amazing video!
Now, since you did a multiplayer tutorial a few weeks ago followed up by a weapon tutorial... could you maybe combine the two and show us how to make a weapon, that is synced via network and actually damages other players?
Good source materials for VR development.
Hi Valem, I was wondering if you could show us how to make a automatic rifle using the unity xr Input system. It would also be nice to see a car,plane,boat tutorial! Please keep on making awesome tutorials!
Thanks Valem for everything.
Could it be the next vr flight training video?
Love it man!
Awesome video! can you make a tutorial on physical hands (Hands that don't go through walls/ floor and that can interact with things without grabbing) ?
second! Any ideas of how to get the XR socket Interactor from part 2 to work with photon?
Oculus Quest 1&2 now fully support unity's DOTS!
Just made a stresstest with 10k flying spaceships smoothly on the quest1.
Looking forward to learn Unity's VR input system and make a character controller that's based on DOTS and integrated to the entity/havok-physic system.
This is just so amazing!
Awesome bro
Could you make a socket wrench tutorial and how to losen / tighten a bolt with it in vr?
Man i have been watching your videos for the past two weeks and based on the xr tutrial series and the full vr body series i am trying to make a physics vr body but i am not there yet . a tutorial on that would be greatly apreciated
You have inspired me to create vr game like if Super Hot and Pavlov had a baby
Honored to be the first one to say that I appreciate your videos!
Hey man its been so long how are you doing? :D
Not the only one! Love your vids can’t wait to make my own stuff! Keep up the good work!
Thanks dougal ❤️
Ive got a question I could really do with some help with!
I want to make an automatic gun for my VR shooter, normally I would use Input.GetKey but with the XR interactor I can call activate in the inspector, but im not too sure how to do that in code. Id like to check for "while input trigger activated" but I dont really know where to start here. Any advice/ tuts are apreciated!
You are a Genius!!!
so cool!
nice bro
In the XR Offset Grap Interactor script did the "OnSelectEnter" work
Valem, I'm looking forward the bolt action.
Awesome!! How hard would it be from there to add recoil? And for this gun to be even more realistic, there should be a fonction that checks if there is a bullet in the gun chamber when changing magazine. This way you don't have to reload the gun if there is.
awesome. can you make tutorial for recoil.
Valem, could you please make a solid base for:
- belt/window socket inventory or half-life alyx inventory system? (whoops! You did that already in one of your videos! Cool!)
- scaling the player up to make a cool god-goliath interaction?
Thank you for your awesome tutorials on which every VR creator can expand!
he did an tutorial about an inventory? do you have the link?
salut valem, merci pour tout, je viens d'entendre parler de VRTK, ça te semble fiable pour faire un jeu VR ? j'ai aucune base de codage mais l'envie de faire un jeu en VR et j'ai du mal à me décider entre Playmaker, Bolt et potentiellement VRTK
Could you make a tutorial on how to make a sword?
You should do a new tutorial on hand keying
so do you not create rigs in Maya or Blender for movement?
I actually tried this with a shotgun and with your two hand grab script but without the animator it doesn’t really work well
Hey Valem thanks for putting out all these awesome videos although it seems that many parts of the code has changed, such as the use XRBaseInteractor has become obsolete and you are now supposed to use SelectEnterEventArgs. I am unable to get it to work. Help please?
Right now if you want to do this without any of those pesky obsolete warning messages, go into XR Offset Grab Interactable Script and change the following FROM:
protected override void OnSelectEnter(XRBaseInteractor interactor)
{
if(interactor is XRDirectInteractor)
{
attachTransform.position = interactor.transform.position;
attachTransform.rotation = interactor.transform.rotation;
}
else
{
attachTransform.localPosition = initialAttachLocalPos;
attachTransform.localRotation = initialAttachLocalRot;
}
base.OnSelectEnter(interactor);
}
INTO:
protected override void OnSelectEntered(SelectEnterEventArgs interactor)
{
if (interactor.interactorObject is XRDirectInteractor)
{
attachTransform.position = GetAttachTransform(interactor.interactorObject).position;
attachTransform.rotation = GetAttachTransform(interactor.interactorObject).rotation;
}
else
{
attachTransform.localPosition = initialAttachLocalPos;
attachTransform.localRotation = initialAttachLocalRot;
}
base.OnSelectEntered(interactor);
}
A video that explains this pretty well-- czcams.com/video/eswe0YMNZNA/video.html
I’m having a problem ☹️. I added a Ak-74 prefab to my scene and fix the animation, so now it plays when I pull the trigger, but no bullet or casing appears. I am using the default SimpleShoot.cs script. What do I need to change it the script
I need help!!! The Link in the description of the video give me a script that didn’t combine with my model leaving me to go to the video you made the script and step by step recreate it and it still doesn’t work
Can you please make a video explaining how to make an object stab through another object?
Nice👌
When I grab slider with the joint on it, it just glitches to my hand and doesn't stay on the gun:/
PLEASE update the full body in unity tutorial its very broken
How do I do this with my hand showing instead of it disappear when I grab the gun
Is there a simple way of also having an option for removing the clip by pressing a button on the hand controller? In the XRinteractable script in the inspector I can only do things with one button on the controller, which is being used by the trigger. Is there a way to add events to the interactable script so that there are events in the inspector for the other buttons as well, not just the primary button?
For my game I created an entire script on the main camera called "Input Manager" that simply used "InputDevice.TryGetFeatureValue" for every input available, so in your case primaryButton or secondaryButton, then puts that in a public variable that other scripts can then access. Then, in the gun script, write:
if(inputManager.primaryButton == true)
ejectMag();
If you want more information about TryGetFeatureValue there is a lot of documentation about it, all you need to do is google.
I've been able to do this in a very simple way, though it may be a cheap solution. Make a script that takes input from the controller for whatever button you want to release the mag from the gun, whenever you press that assigned button, disable the XRAmmoSocket script that you made and it will drop the gun and reset itself upon its reenable automatically. Hope this helps.
I have a problem where when I grab the gun by the slider it glitchest out meaning when I grab the gun from the table without grabbing the grip it holds it by the slider help! :D
can someone please tell me why my configurable joint is relative to the world and not relative to the gun. it only moves on the world x axis but not the gun x axis
Can you make a realistic Shotgun tutorial?
Accidentally here early
HELP!!! I disabled the animator for the gun, but the slide still disconnects and there is a blue and sometimes red version of the slide. is there anything I can do to fix this?
Some one has issue when gun is goes thru the table, and gun loader is collide? How to remove this?
Make a tutorial on how to make buttons
For some reason my configurable joint randomly stops working. Any ideas why?
Could you please make tutorial on how to chop tree/harvest wood in VR? And inventory system?
perfektne videa...mam otazku...mozes urobit aj video ako vytvorit aspon zakladne vr menu v hre aby bolo prepojene s hrou a malo zive tlacidla. VR menu..
For some reason if i assign the connected body on the slider the gun starts flying does anyone know how to fix this?
i couldn't understand why the "axis" property was set to 0,0,-1. Why exactly do we need the joint arrow to face that particular direction?
Because the joint only needs to move in the direction of pulling back the slider. Which is in the direction of the red arrow @ z = -1
Love your videos! Anyone have problems with the gun slide? I have to delete the slide's XR Grab Interactable component and recreate it with the same values every time I reopen the Unity editor (2020.2.7f1c1), otherwise, the gun slide would not be able to slide.
I have a problem were when I try to grab the slider, I just grab the guns grip out of the hand that is already holding the gun, how do I fix this?
I just continued using the normal XR Grab Interactor instead ofthe offset one
how can u play your game using virtual desktop?
Hi there :) There is an error in the XR Offset Grab Interactable script made by Valem. The XR Interaction Toolkit has been updated and now the OnSelectEnter method dosn't exist anymore. To make it work you need to replace "OnSelectEnter" by "OnSelectEntering" ;) Hope that does help you
Peace :)
lol i commented the same thing didnt see yours!
For me the Offset grab still didnt work even though i changed it in the offset code so i went ahead and use the normal XR Grab Interactable on the slider but when i now go into the simple shoot funtcion the onSelectEnter does not work for me because it then says the "AddMagazine" next to it says: "cannot convert from "method group" to UnityAction" and when i use the OnSelectEntering it says ''XRBaseInteractable.OnSelectEntering is inaccessible due to its protection level" do you know how to fix this issue?
Is there any way to add haptic feedback when you shoot the gun.
private ActionBasedController _XRController;
void Start()
{
_XRController = transform.parent.GetComponent();
}
// where you want to do it, add this
_XRController.SendHapticImpulse(1f, 1f);
i keep getting this error when trying to copy over the xroffsetgrabinteractable script
Assets\XROffsetGrabInteractable.cs(26,29): error CS0115: 'XROffsetGrabInteractable.OnSelectEnter(XRBaseInteractor)': no suitable method found to override
i have no clue what to do
same!
@@reallocal i fixed it by deleting another script under the same name that was interfering with it but now i've got a error CS0246 for namespace magazine in the simple shoot script, hope your able to fix your problem bud
@@donttouch1148 dang, ok. I'll let you know if I figure anything out.
try this script i changed it a little:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit;
public class XROffsetGrabInteractable : XRGrabInteractable
{
private Vector3 initialAttachLocalPos;
private Quaternion initialAttachLocalRot;
// Start is called before the first frame update
void Start()
{
//Create attach point
if (!attachTransform)
{
GameObject grab = new GameObject("Grab Pivot");
grab.transform.SetParent(transform, false);
attachTransform = grab.transform;
}
initialAttachLocalPos = attachTransform.localPosition;
initialAttachLocalRot = attachTransform.localRotation;
}
protected override void OnSelectEntered(XRBaseInteractor interactor)
{
if (interactor is XRDirectInteractor)
{
attachTransform.position = interactor.transform.position;
attachTransform.rotation = interactor.transform.rotation;
}
else
{
attachTransform.localPosition = initialAttachLocalPos;
attachTransform.localRotation = initialAttachLocalRot;
}
base.OnSelectEntered(interactor);
}
}
For me the Offset grab still didnt work even though i changed it in the offset code so i went ahead and use the normal XR Grab Interactable on the slider but when i now go into the simple shoot funtcion the onSelectEnter does not work for me because it then says the "AddMagazine" next to it says: "cannot convert from "method group" to UnityAction" and when i use the OnSelectEntering it says ''XRBaseInteractable.OnSelectEntering is inaccessible due to its protection level" does anyone know how to fix this issue?
I'm having the same issue, did you figure it out?
@@alexsayres9445 nope still couldn't figure it out, had to scrap the whole reloading idea, sorry!
@@alexsayres9445 Same here, any updates ?
yea im also having that issue
@alexsayres9445 i know this is very late but if you change:
public void AddMagazine(XRInteractable interactable)
to
public void AddMagazine(SelectEnterEventArgs interactable)
it should fix it
Make a how to make a fps game tut
does it work with index?
can some one sent me the simple shoot script i have some problem but i cannot solve it
There's another really annoying issue with the gun, when the user grabs the gun, he can gran the slider instead of the gun itself. Any simple fix ?
Edit: You can also grab the magazine from inside the gun instead of the gun itself, which feels stupid
Likely you need many more enabled/disable states then like he has done in this tutorial a couple of times. Disabling the slider grab interactible when the gun is not being held in your hand as well as disabling the grab interactible of the ammo clip when it its parked inside the gun. I actually think its wise to just hide the whole clip from the scene when its parked inside the gun and similarly just show it again when the user is trying to grab it again from the bottom of the gun.
@@64jcl does not work. socket and grab scripts is connected to rigidbody, so when you disable it gameobject start falling.
@@development6477 set the rigidbody to kinematic
Salut @Valem, est ce que tu est Français et peut tu faire des videos en français si c'est le cas ? mercii 😁
Why it's so fast?
please make it multiplayer
my gun flies around, why?
Might be a bit late but... it's called a slide, not a slider. It has the same job as a charging handle on a rifle, to put a round in the chamber so that the hammer can strike it and fire the bullet at the end of the round. The casing is then extracted. =P
Correct. But the unity package (from the asset store) itself calls it "slider", so for the sake of tutorial consistency, it doesn't matter.
your tutorials are legendary but my god it is maddening following them today because everything is just deprecated and nothing works and its all xr and ixr and interacbles and interacble object and it never works it always complains its deprecated and when you use the non deprecated stuff you can never just get the gameobject and the unity docs are incomprehensible
omg i hat eit so much
get it to work:
xrsocketinteractor, selectentereventargs(), args.interactableobject.gettype().getproperty("gameobject").getvalue(interactable, null) as gamobject;
but now how can i tell the socket to drop the mag via code/when a button is pressed
i hate hate hate these stupid frameworks so so so much, they are so bloated and shitty and obnoxious and unintuitive its just so bloody horrible my bloody god
so going to try making a custom socket interactor, as well as eventually a custom joint based grab interactable
jesus it is so indescribably infuriating like my god why cant i just say "socket.forcedrop" or "socket.getgameobject" like what the hell i hate it so much
scripting is fun but bashing your head against your wall for 10 hours straight wondering how the hell to get frameworks to work is absurd
Go check out my new channel Valem Tutorials, it has everything updated !
@@ValemVR will do!
This in Multiplayer 😨😀😀
KEYS
I give up with Unity. 95% of the assets on the store are pink and auto upgrading them to URP doesn't work. Learning Unity is 10 times harder when you can't find working assets.
its just because urp is new. most of the new assets that are published have urp versions. and you just have to change the shader type from standard to urp to make it work on the old ones
i create a new material and just add the textures that come with the asset
hi Valem, this is great except there in one MAJOR PROBLEM. the XRGrabInteractable on the slide is randomly masked by the XRGrabInteractable on the gun
unity gives this warning
A collider used by an Interactable object is already registered with another Interactable object. The Slide (UnityEngine.BoxCollider) will remain associated with Slide (XROffsetGrabInteractable), which was registered before PlayerPistol (MyGrabInteractable). The value returned by XRInteractionManager.TryGetInteractableForCollider will be the first association.
so sometimes it works great then for no reason, trying to grab the slide results in grabbing the gun. i've spend 2 days on this and got nowhere. any help would be greatly appreciated. thanks
replying to myself but i finally got it working but using an entirely different system to XRGRabInteractable. i put a trigger collider on the slide, (make sure there is no regular collider on the slide), then catch trigger enter and exit from the left hand. then detect grab with left hand while inside trigger zone. then do some math to figure out if left hand is dragging back. the same 2 points, the start and end point of the slide movement. then use Vector3.Lerp to calculate a position for slide based on hand position. don`t forget to disable animator at start of slide and enable at end of slide which will put the slider back in its home position. its a shit load of work but works great without weird hand interactions. keep the grab handle collider quite small so your left hand doesn't accidently touch it.
Hi man thank you for giving a response here it will help a lot future people that come on the video ! :)
@@TheSateef I'm trying to make a slide, that has no spring, meaning it'll stay in the back position when let go and stay in the forward position when let go (its a weird gun). could ya maybe release ur slide script code so i'd have a starting point for it?