Realistic Gun in VR - Part 1
Вставка
- Опубліковано 3 жов 2024
- 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.c...
First :)
I don't have the Xr grab intractable component can you help?
I HAVE A HUGEEEEE ISSUE with firing the Gun, the bullet spawn lags behind just a small distance behind, no matter what direction I move in, depending on speed and height, like if I am running or Jumping, or just side strafing, the bullet spawnpoint shifts side to side, it sucks, please help. If you could point me in the right direction or offer your advice, I would be forever in your debt. So, Basically the bullets are spawning from where I was a second or so before, rather than from where I am. It makes the bullet spawnpoint to shift side to side, Help....Please.
Here is the code I am using
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Gun : MonoBehaviour
{
public float speed = 80;
public GameObject bullet;
public Transform barrel;
public AudioSource audioSource;
public AudioClip audioClip;
public void Fire()
{
Instantiate(bullet, barrel.position, barrel.rotation).GetComponent().AddForce(barrel.forward * speed);
audioSource.PlayOneShot(audioClip);
Destroy(bullet, 2);
}
}
@Valem i know you have a lot to do but if you manage to answer this that would be awesome
How would this work with the OVR plugins from oculus
nice
@@GoldFishNoMore you have to go to package manger press the plus type com.unity.xr.interaction.toolkit
was trying to make a vr gun with realistic loading like this myself. lets just say...im glad this new tutorial came out
This is exactly what ive been looking for
I wanted to ask, with the Hinge Joint you used, when the hand grabbing is is like 0.5 units away or further, the Joint starts glitching and teleports the object around.
It is attached to a grabbable object.
I learned about your channel just yesterday, and today when I was researching how to make a realistic gun for a VR game you happened to upload that today lol. Awesome tutorials :)
I suppose you are putting the 2 box colliders to be able to pull the top of the gun when loading? It could be nice if you could justify it in your videos. People are beginners and explaining even quickly this kind of thing could really be great (I'm a beginner too haha, I'm learning VR with you!)
Thanks! This is some good insight into VR.
"A programmer makes the code. But a good programmer takes the code" Valem - Oct 29, 2020
Are you reincarnation of Brackeys? 🤔
Yes hs is
I’ve been into game development for a while, I recently received a quest 2 and man, the feeling of stepping into your own project is, truly unreal. Thank you so much.
No, it's not Unreal, its Unity! lol
I have been learning so much from these videos and have a few prototypes up and running on the Quest. Thank you, Valem!
For anyone with PINK MATERIAL happening to them, it is basically that you are using a newer version or adifferent pipeline, to solve it I had to change the material itself from standard to URP-Lit and put in the base-map of the Lit material what would be in the albedo option for the standard material.
Thank you!
Everytime I hear him say "Nokobot" I think he's saying knucklebutt
My favorite gun out there, -Valem 2020
How can I make it shoot faster? I looked through the script and it seems like it would be the "ShootPower", but I increased it by a lot and still doesn't work. I am wondering if it has to go through the whole animation before it can shoot again. If so, I guess there is no way around this unless you go into each animation and make it shorter. Anyone else have a better idea? Great video, appreciate it. @ValemVR
Awesome, thank you
Will you be making an updated full series on VR development? Alot of stuff I feel is outdated from the original set of tutorials
7:33 - No truer words have ever been said!😂 Love your work, Valem
yeah i loved that damn line.
Thank you for making this! I needed this so much :)
Thank you very much for the tutorials, they're excellent. However, I do have a complaint: can you please remove your face from the tutorials? Nothing personal you're a handsome guy, but most of the times you're covering the properties panel and it's so annoying. I really hope this new bad habit in UA-cam tutorials stops. Thanks again for the content brother.
I completely disagree, I did not find a single time in this tutorial that I needed to see the properties panel and couldn't, no hate towards you I just wanted to let Valem know that not everyone that watches thinks the same as your comment :)
hello valem i used to be a patreon but i can no longer pay from credit cards in my country (Lebanon). I was wanted to say thank you for these great videos, also i wanted to ask you if you can make a vr body kinda like last series you did but with xr since so much have changed. Thank you
hi as a beginner developer should i buy rift s or quest?
my gun is complety purple
anyone know why
Hi Valem, it would be really cool if you could do something on physics based vr, something like a boneworks system.
That would be pretty cool, although, after all, that's an entire physics system that he has to make, which already took a whole team of developers years to make.
Hey Valem, I tried making these scripts work on a shotgun but the shotgun just switches hands instead of letting me grab the pump. Any ideas on what could be causing that?
it doesnt show pull tigger as a function
I have the same problem
What does the code say after tempCasing.GetComponent().AddExplosionForce(Random.Range(ejectPower * 0.7f, ejectPower), (casingExitLocation.position - casingExitLocation.right
HELP
Anyone have an answer to this I'm in the same boat
@Asset Reviewer i got it my friend "tempCasing.GetComponent().AddExplosionForce(Random.Range(ejectPower * 0.7f, ejectPower), (casingExitLocation.position - casingExitLocation.right * 0.3f - casingExitLocation.up * 0.6f), 1f);"
I am developing the game but how can i test it without the vr glasses?
this enabled me to use my first code in vr man thanks heaps bro
Oh my god yes I’ve been looking for this, I just learned how to instantiate game objects using a VR button, and this would be really cool for doing randomly spawned targets like cubes
sexyy, also 100th comment
Is it possible for my to use my own model and create this gun?
Can you give me a link to XR tutorial?
For anyone who wants the bullets to despawn. Place under // Create a bullet and add force on it in direction of the barrel this:
GameObject tempBullet;
tempBullet = Instantiate(bulletPrefab, barrelLocation.position, barrelLocation.rotation);
tempBullet.GetComponent().AddForce(barrelLocation.forward * shotPower);
Destroy(tempBullet, destroyTimer);
does this go under the code underneath that comment?
MAKE THE SAME TUTORIAL WITH OVRPLAYER OCULUS
does it work with Photon Pun 2
is there a way this will work with the IK Rig? because im working on a multiplayer shooter inspired by Pavlov and TTT from Garry's Mod
It should. If you followed this tutorial, the ik tutorial and custom pose tutorial this should work perfect, best of luck in your game!
Actually this is the best UA-cam Channel
without you Valem, i would be oh so lost
Is this a jojo reference
i have been waiting for a video like this for so long
Does it work for steamvr?
How is your hand invisible?
GetButton doesn't work with the new input system
why is it that everything I try to script ends up never working? I type the exact same things as you do and It just doesn't work.
Why is it that I can buy an arcade gun with very realistic recoil for a hundred dollars from a hundred places but a can’t a recoil gun in VR is near impossible???
When I use my own gun model with discrete RB and Kinematic movement on the XR Grab Interactable, there is a lot of stutter whenever I move the object around or whenever the player moves :(
I've had a issue too where If I move a object with my hands its stuttery even though my hands are running completely smooth.
@@MrVic-qu9qh yup, this.
@@keelanbowker-obrien2222 I think the issue is that the objects are running at a different max framerate but I don't know how to increase the objects frame rate.
Is there any way to add haptic feedback when you shoot the gun.
Yes, on the XR Direct Interactor, usually on each controller, there are options for haptics.
im planning on using this asset for my game, the asset isn't copyrighted is it?
how do i point it in the right direction or say where it have to grab bc i dont wanna have a really relistic gun and have a different gun model i also wanna have a sword but its grabing on defaut where the axis is. pls how do i fix this
Hey m8 can you make a updated version of this for the tutorials channal
For some reason this just instantly breaks my project on import (App stuck on 3 Dots). I don't even need to add any gameobjects from the asset to the scene. Just importing the asset alone causes it to break. I've tried other assets and they don't cause the issue.
does this also work for valve index, working with unity's xr plugin (cause u did a tutorial for steamvr before )??
Can you use the XR script to make it playable in Oculus quest?
I used the Pivot point for the gun so my hand was visible but my bullet just goes flying upwards? does anyone have the same problem?
it says parameter fire does not exist
what do i do
I can't open the simple shoot script, does anyone has the same issue? Or does someone have a solution?
Does it work with index?
Can anyone confirm if the handpresance script still works
Yes yes yes yes yes yes
valem: you might be mad because I didn’t create my own script
Animators & 3D modelers:...
Btw I love ur vidds
Its ok
for some reason the gun has been falling through the floor do you know why?
You must add a Rigidbody component to your floor and make sure that the option is Kinematic is selected and the option use gravity is not selected
@@doubleaxe18 thx(:
Mine are insane, I started VR dev when VR first came out, I've been doing realistic guns for many years now. I even do real projectiles.
Looking forward to seeing you add your skills for realistic guns into your Unity Tutorials you’ve already made!
Does this work for oculus quest
first vid where you use quest 2 :)
with the xr grab can i use distance grab instead?
Could you make a download where we would just have to move an entire xr rig and we wouldn't have to set it up ourselves. I'm having issues with getting the hands to be in the right place.
They are further out and to the left some. I've tried everything I know to fix it and it dosent work
Some recoil would be nice too :D
For anyone wondering what the code is after
"tempCasing.GetComponent().AddExplosionForce(Random.Range(ejectPower * 0.7f, ejectPower), (casingExitLocation.position - casingExitLocation.right"
it's:
" - casingExitLocation.up * 0.6f), 1f);
tempCasing.GetComponent().AddTorque(new Vector3(0, Random.Range(100f, 500f), Random.Range(100f, 1000f)), ForceMode.Impulse);
Destroy(tempCasing, destroyTimer);
}
}"
hi man great work, but how to add recoil ?
(sorry im really late) not really sure, maybe you could add it in the animation, or try having a force constantly pushing it to the default position, then rotate/move it upwards so that the recoil would work with multiple consecutive shots
48th
gun has no recoil?
Какой же ты молодец!!!!!!!! Respect
Nice
How can you delete the hand when holding a gun?
(sorry im really late) you probably wouldnt want to delete it, or even disable it because thats also whats being tracked. Maybe instead you could just disable the mesh renderer so you wouldnt see it
when i change the trigger function to what you did, it just gives me a error saying, "Assets\Nokobot\Modern Guns - Handgun\_Demo Assets\SimpleShoot.cs(81,1): error CS1022: Type or namespace definition, or end-of-file expected"
Is there anyway i can fix this?
edit: im still waiting for a answer
WHY DOES THE GUN FALL THROUGH THE CUBE
floor collision maybe
Thank you so much for this tutorial, I tried on my own and It didn’t work at all.
What was the issue? :o
I am brand new at learning code was the issue honestly.
I wrote it the wrong way, your tutorial worked it was my attempts before this that didn’t work
Is he French?
Does it matter?
@@AtomsForFuel I am French too so I guess no
belgium
rEaLiStIc ShOoTiNg
Recoil be like: im bouta end this mans whole career
Great
second :)
18th
Yessss
THANK YOU NOW I CAN MAKE MY BACKROOMS GAME