Hitscan Guns with Bullet Tracers | Raycast Shooting Unity Tutorial

  Рет қаралды 89,257

LlamAcademy

LlamAcademy

Күн бұрын

Пікірлер: 140
@lethn2929
@lethn2929 2 жыл бұрын
Looks like putting in sensible and accurate tracers is a bit more complicated than I thought, which is weird but I'm glad I found an up to date video on this topic because I was getting frustrated only being able to see 10 year old videos in javascript.
@LlamAcademy
@LlamAcademy 2 жыл бұрын
Glad it could help you!
@lethn2929
@lethn2929 2 жыл бұрын
Here's what I ended up with after poking around the internet some more. To make the bullet spread more skill based you would obviously add the spread changing depending on the crouch and how long you've had the mouse button held down. if (Input.GetMouseButton(0) && Time.time >= nextTimeToFire) { float bulletSpread = 0.04f; Vector3 bulletSpreadDirection; bulletSpreadDirection = gameObject.transform.forward; bulletSpreadDirection.x += Random.Range(-bulletSpread, bulletSpread); bulletSpreadDirection.y += Random.Range(-bulletSpread, bulletSpread); bulletSpreadDirection.z += Random.Range(-bulletSpread, bulletSpread); if (Physics.Raycast(transform.position, bulletSpreadDirection, out hit, Mathf.Infinity)) { nextTimeToFire = Time.time + 1f / fireRate; Instantiate(bulletTrail, transform.position, Quaternion.identity); lastHitPoint = hit.point; if (hit.collider.gameObject.tag == ("Enemy")) { GameObject enemyObject = hit.transform.gameObject; enemyObject.GetComponent().enemyHealth.decreaseEnemyHealthPistol(); } } }
@Goozeeeee
@Goozeeeee 2 жыл бұрын
I know others have probably pointed this out, but LERPING is going to cause a huge problem since bullet travel will always take the same time. Meaning bullets shoot SLOWER if you're shooting at close targets (like the ground in front of you), and REALLY FAST if you shoot say- the skybox. You'd probably be better off just giving bullets a static speed and destroying them after they get within a certain distance of a target.
@LlamAcademy
@LlamAcademy 2 жыл бұрын
You are right! That is an issue with this implementation. I’ve added a comment and info in the description pointing to a way to achieve it with a fixed SPEED lerp instead of fixed TIME lerp so your bullets don’t slow down!
@herohimself
@herohimself 11 ай бұрын
@@LlamAcademy there's nothing about this in the description?
@LlamAcademy
@LlamAcademy 11 ай бұрын
@@herohimself It is the first resource listed: ⚫ Bouncing Bullets, Handle Misses, and Constant Bullet Speed: kzbin.info/www/bejne/fZy2pYpuYrZohpI Here is a direct link to the completed PlayTrail coroutine along with the explanation of how it works: kzbin.info/www/bejne/fZy2pYpuYrZohpI?t=458
@herohimself
@herohimself 11 ай бұрын
@@LlamAcademy Thanks. I missed that xd
@ignatiusreilly8280
@ignatiusreilly8280 6 ай бұрын
This is so neat, I've been looking for a way to avoid physics ricochet calculations for my pew-pew towers, thanks very much for showing how to do this with just raycasts.
@LlamAcademy
@LlamAcademy 6 ай бұрын
You're very welcome!
@poobagification
@poobagification 2 жыл бұрын
I like that you show all these useful asset packs that are free and super useful. That plus the content explanations makes for great value.
@GasGasGas2024
@GasGasGas2024 2 жыл бұрын
Man seriously you had to be uploading a impressive tutorials like this before a long time ago bro, You are awesome indeed!.
@Fenrigore
@Fenrigore 8 ай бұрын
Огромное спасибо! Очень полезная информация и ничего лишнего!
@Stratoscaster
@Stratoscaster 9 ай бұрын
For anyone else that gets multiple bullet impacts per shot, under the Emission settings inside the Particle System component, set the "Rate Over Time" to be the inverse of whatever your duration is. E.g. duration 0.25 = rate over time of 4
@hananbenshabat9757
@hananbenshabat9757 2 жыл бұрын
this is the best channel ive ever seen for this content, u deserve more subs, thanks u really helped me out with this video
@LlamAcademy
@LlamAcademy 2 жыл бұрын
🙏 I appreciate that thank you!
@Banaaani
@Banaaani 2 жыл бұрын
Very good stuff. Few problems thought. The speed of the trail changes on how far your hit point is. Also, if there is no hit point, like shooting the sky, there is no trail at all. There are some fixes, but I ended up using very brief Linerenderers between the gun and hit point anyways.
@LlamAcademy
@LlamAcademy 2 жыл бұрын
Yeah the "shooting" when the raycast doesn't hit is something I really should have included in the video. That's answered in a pinned comment. Regarding the speed of the projectile. That's a fair point as well. I'll think about that solution and see what I come up with. For what you said you used, that's a very different look, but if it fits your game that's great you have a working solution
@eren_guneri
@eren_guneri 2 жыл бұрын
Hey, regarding the speed of the projectile, I'm not sure why but I did something like this and it kinda works? idk. time += Time.deltaTime / hit.distance * 100f;
@LlamAcademy
@LlamAcademy 2 жыл бұрын
Thanks for replying to remind me to provide an update! See fixed speed lerping in the Lerping Fundamentals video: kzbin.info/www/bejne/f6rQdXqhr9x9qtU for how to resolve this. I think what you’ve done is just made it move very quickly so the difference is less noticeable versus what was implemented in this video. To see it fully integrated look at the bouncing bullets video: Raycast/Hitscan Shooting With Ricocheting Bullets From Scratch! Unity Tutorial kzbin.info/www/bejne/fZy2pYpuYrZohpI
@eren_guneri
@eren_guneri 2 жыл бұрын
@@LlamAcademy thank you for your reply, this is very very helpful.
@Thouova
@Thouova Жыл бұрын
Well made and easy to implement to an already working weapon system!
@lee1davis1
@lee1davis1 2 жыл бұрын
An easier way to do all this is to create a prefab with a trail renderer set the time at creation based on the distance shooting. Then next frame move the new game object to the hit point. The trail renderer does all the work.
@lethn2929
@lethn2929 2 жыл бұрын
Would there be potentially accuracy problems using this method though? I'd have to look into that, I don't use trail/line renderers very often, if the programmed method works and works well I'd probably be more inclined to rely on that but it would depend on how well your method works. I've tried setting up tracer fire myself before with various methods and it can be very jarring to the experience when you fire and it's out of sync etc.
@LlamAcademy
@LlamAcademy 2 жыл бұрын
An interesting idea! I'll have to take a look at that as well. Thanks for the suggestion!
@a3dadventure79
@a3dadventure79 10 ай бұрын
yep, that works just fine! thanks so much! public void Initialize(Vector3 startPos, Vector3 endPos) { StartPosition = startPos; EndPosition = endPos; } // the frame after when it is instantiated private void Update() { MoveTrailToEndPosition(); } public void MoveTrailToEndPosition() { transform.position = EndPosition; Destroy(gameObject, trailRenderer.time); }
@a3dadventure79
@a3dadventure79 10 ай бұрын
DOTween does a nice job too with the right values. private void Update() { AnimateTrail(); } // DOTween animation for trail to simulate bullet public void AnimateTrail() { // move/animate our trail transform.DOMove(EndPosition, trailMoveDuration).OnComplete(() => { // and destroy it after the trail fade out time Destroy(gameObject, trailRenderer.time); }); }
@LlamAcademy
@LlamAcademy 2 жыл бұрын
Edit: If you check out the GitHub repository, that now has some fixes to address the most common fixes requested in the comments: 1. Bullets move at a fixed velocity specified on the gun. In this video they always move with a fixed TIME so if they travel a short distance, they move slower. 2. Bullets now shoot if you don't make contact with something with the Raycast. In this video we only cover if you do make contact. 3. You can now hold left mouse button to continually shoot instead of having to spam left click to shoot rapidly. ---- Want to know how to handle shooting even when a Raycast misses? What about having Bullet ricochet/bouncing mechanics? Constant bullet trail speed? 👉👉kzbin.info/www/bejne/fZy2pYpuYrZohpI Thank you all who raised some of those concerns with this implementation 🙏
@ronigleydsonvilasnovas8067
@ronigleydsonvilasnovas8067 2 жыл бұрын
So much useful information and an amazing tutorial as always. All this in less than 12 minutes.
@LlamAcademy
@LlamAcademy 2 жыл бұрын
🙏🙏🙌
@Destroyanad
@Destroyanad Жыл бұрын
For anyone curious, here is a different way to add spread to each bullet, while only having changed one value. public float bulletSpread = 1f; direction += new Vector3( Random.Range(-bulletSpread, bulletSpread), Random.Range(-bulletSpread, bulletSpread), Random.Range(-bulletSpread, bulletSpread) ); This is in the GetDirection() method under if (AddBulletSpread) {}
@combine_soldier
@combine_soldier Жыл бұрын
direction = Random.insideUnitSphere * bulletSpread ;
@alexbailey1204
@alexbailey1204 2 жыл бұрын
Make sure to have some sort of wall boundaries in your level. Otherwise, the gun will 'shoot' with the muzzle flash but no trail will spawn because the raycast is not hitting anything. Invisible walls works just fine
@LlamAcademy
@LlamAcademy 2 жыл бұрын
Yes! In this implementation I didn't handle misses. I made another video to handle bouncing bullets, constant bullet move speed, and handling misses here: kzbin.info/www/bejne/fZy2pYpuYrZohpI
@alexbailey1204
@alexbailey1204 2 жыл бұрын
​@@LlamAcademy Thank you for linking the github repo so we can truly understand the code and play around with it! Surprisingly a lot of KZbin tutorials do NOT do this so it is very appreciated.
@karacter3369
@karacter3369 11 ай бұрын
my bullets are really slow for some reason, like reaaally slow, but i'll fix it somehow, thanx for the tutorial! edit: I just needed to set the time on the trail renderer object to something lower, lmao
@saadbutt2186
@saadbutt2186 2 жыл бұрын
Thanks sir for such good explanation
@LlamAcademy
@LlamAcademy 2 жыл бұрын
You are welcome 🙏
@stylie473joker5
@stylie473joker5 2 жыл бұрын
Thanks a bunch i'm planning to make a simple shooting game this is gonna be helpful
@LlamAcademy
@LlamAcademy 2 жыл бұрын
You're welcome! I hope it comes out nice!
@quarantinethis8981
@quarantinethis8981 2 жыл бұрын
You good sir have earnt yourself a subscribers. Literally needed this a week ago so your timing is perfect. Keep up videos like this, it was spot on and should be easily integrated into my game. A very needed thing as my game is a racer that involved 12 different directional buttons.
@LlamAcademy
@LlamAcademy 2 жыл бұрын
That's awesome to hear! Glad it could help you out in your game!
@quarantinethis8981
@quarantinethis8981 2 жыл бұрын
@@LlamAcademy It unfortunately, didn't end up helping :( I have just spent 6 hours trying to impliment your script on the most bog standard of screens you would ever see. The serialization didn't even show up :( Below is a bit of a rant and a bit of steam to say why it didn't work (when it really should be, I think my Unity hates me). Your videos are great, I like your presentation and I like how you explain things and the way you edit and apply effects to your videos when needed. I found it easy to follow, engaging and understandable. Below are some of the reasons and some general tips I think would help you stand out from the crowd on general tutorial videos. Could you please do a video that explains the following: Insert Gun on Unity, say a single cube Attach Gun/Shooting script GetButton Fire1 This does a RayCast and Trail and Impact and gives damage with recoil. So all that's needed in the scene, is a plane for the ground, a sphere to hit and a rectangle stick for the gun. No damb animation or bones, or anything else. Granted, I do understand putting a UI with an aim piece in might be needed as well. But just the bare minimum to do any of your videos. Way too many KZbinrs put far too much things in. People learning aren;t looking for a mass game to follow to create on KZbin, we are generally looking for hard to explain answers with scripts, that (like shooting) have many different answers. To see one person do a Shooting Playlist, breaking down every single way to code a gun, would be amazing. And I don't mean heres the 2D way and heres the 3D way. I mean, here's multiple ways to get the same effect in 3D or 2D, it just depends which one is gonna work in your script. As someone who uses Udemy and KZbin I can say that KZbin use way to much of the following things I think you should avoid NO CUSTOME MADE PACKAGES DO NOT DOWNLOAD OR USE ANY PACKAGES THAT ARE NOT IN UNITY FOR CODING TUTORIALS, show the viewer how to make the impact system or muzzle flash. ONLY USE THE BASIC UNITY and only use the stable version, 20 version might now be stable, I'm not sure ALSO PLEASE SHOW HOW TO CHANGE THE IMPACT YOU USE, no matter how I change it, it takes 1 second to implement the impact particle system, this is an important factor, a very important factor, over looked Every single video I have watched on this subject is different, and none of them work properly or unity and visual studios has decided to be updated and therefore, just work the same way. I follow them step by step, even having to pause to make sure the writing and the collons and brackets are in the right place. But no, Unity just doesn't want to do it. Either that or the tutorials are too quick, no speaking, ad extra information that isn't needed for "this is the answer to a SPECIFIC question", we do not need "here's a load of fluff and somewhere is your answer", luckily you don't add too much fluff. However, it would be really great if you did your normal videos, but at the end you redid the process, without the explaining as this makes every single tutorial video jaring and hard to follow. Yes we need the explanations for tools and coding, how it interacts with each other and so on. But when it comes to then sitting down and following along and implementing, we just need a screen to look at. I understand this was a big rant and a bit of steam. Your videos are good, I like your presentation and I like how you explain things and the way you edit and apply effects to your videos when needed. The above are just suggestions. But please do the most basic of videos, on shooting a gun with a tracer that you can. I think I have to use 3 different tutorials to actualy get a script that is needed for my game and figure out how to integrate them. Sorry for the length, had to cool down and steam off, kinda hopes it helps you, either way, keep up your great work
@chiperchiper1782
@chiperchiper1782 2 жыл бұрын
Thanks man, really helpful video. I love your channel!
@LlamAcademy
@LlamAcademy 2 жыл бұрын
You're welcome and thank you! 🙏
@bnenanadev
@bnenanadev 3 ай бұрын
In my current weapon system the raycast is "cast" from the camera and not the gun. How would I be able to raycast from the gun while still maintaining accuracy? Or is there a way to cast a trail from the gun to the point where the raycast hits an object?
@LlamAcademy
@LlamAcademy 3 ай бұрын
You might consider checking out this video in my scriptableobject gun series where I compare the different options for accurate aiming kzbin.info/www/bejne/rmmodKOEjLKgl8k
@fastsnail9012
@fastsnail9012 2 жыл бұрын
hey, I love the video, it's helped me a ton, but how would you make this work for shotguns?
@LlamAcademy
@LlamAcademy 2 жыл бұрын
Shotguns are a lot of fun, luckily they are also relatively simple to implement! You can choose how many pieces of buckshot/shrapnel for the gun to shoot, and simply fire that many bullets at once. Remember to increase the shoot delay or you'll just multiply the number of bullets per second!
@cyco3oy
@cyco3oy 2 жыл бұрын
Brilliant
@seymursm
@seymursm 11 ай бұрын
Hi, thanks for the clear explanation and details. I have one question. Does it affects the performance that starting so many coroutines for every bullet in this case? As far as I know so many coroutines are not memory efficient to use.
@LlamAcademy
@LlamAcademy 11 ай бұрын
I haven't encountered any major issues even having hundreds of bullets at once. The bottleneck usually ends up being the GameObject architecture at that point. I think in most cases you'll end up having to swap to an ECS model before the Coroutines for this are the bottleneck. But it's always important to profile on the specific target hardware to understand the true performance constraints you have. I used this same concept in my mobile and even on mid-tier android devices this was not a meaningful use of CPU/Memory in my game.
@uanlock28
@uanlock28 2 жыл бұрын
That's pretty interesting tutorial.
@LlamAcademy
@LlamAcademy 2 жыл бұрын
Thank you! It was a fun one!
@Kolbein837
@Kolbein837 2 жыл бұрын
Great tutorial. I have a slight issue with the trail. When I'm at (0,0,0) the trail works fine, but when I'm way off center of the map, the trail does not go straight forward like it does if I actually hit something. I'm using your newest script for GitHub. It seems to go towards a certain point in the direction I'm aiming, but as if I was standing in (0,0,0).
@LlamAcademy
@LlamAcademy 2 жыл бұрын
You are right! On this line where we miss: StartCoroutine(SpawnTrail(trail, transform.forward * 100, Vector3.zero, false)); You’ll need to add in the BulletSpawnPoint.position + transform.forward * 100 I just noticed I ran into that same problem on my latest video. I’ll push an update to this repository later today. Thank you for pointing that out!
@Kolbein837
@Kolbein837 2 жыл бұрын
@@LlamAcademy Thank you for the quick reply! Loved the video!
@LlamAcademy
@LlamAcademy 2 жыл бұрын
@@Kolbein837 🙏 the repository is updated to miss better now! Thanks again!
@gunvirdhesi6672
@gunvirdhesi6672 Жыл бұрын
Great Vid! When you run and shoot, the bullet trail isnt in front of the gun, it goes behind, so it looks glitchy. How do I fix this?
@LlamAcademy
@LlamAcademy Жыл бұрын
Hi! This is a common problem in games, including in popular games such as The Ascent, Counter-Strike, and Battlefield. I answered this question on the ScriptableObject Gun Series here: kzbin.info/www/bejne/pqjUaHlrecqEpKs&lc=UgwVo6Y_izFMXw3mj9N4AaABAg.9htKuOccZ2S9hwt7-ONnJC "I played a few games with shooting today just to really inspect the bullet trails and looked at a couple more online. There were generally 2 ways I saw trails were dealt with: 1. They have longer trails like the default configuration here, and when this is the case, when the gun/player was moving quickly, the same behavior you see here, happened there. I specifically was looking at top-down or 3rd person games this is more prominent in. You can see the same behavior in "The Ascent" for example. 2. Bullet trails are very fast and short-lived. First Person shooter games typically have this. For example Counter-Strike and Battlefield V were some examples I looked at here. They technically have the same behavior, but because the trails are only displayed for a couple of frames, it's really hard to see. If you lower the "Duration" property to something low like 0.01 or 0.025 you can see a very similar effect to what you see in those games."
@echoecho39
@echoecho39 2 жыл бұрын
So I installed everything you said to, and then immediately, I do not have a script called "Player Input", so I can only assume it's from a package you didn't mention, or from another video.
@LlamAcademy
@LlamAcademy 2 жыл бұрын
Hi! Player Input comes from the new Input Sysrem and is automatically on the prefab for the player controller I used from the Starter Assets pack. In the section at 2:58 we create a PlayerAction script to handle the shooting. These two together work to do the shooting of the gun. Remember all videos have the full project available on GitHub so you can check that out to see if you have something slightly different than what I did.
@echoecho39
@echoecho39 2 жыл бұрын
@@LlamAcademy Uh, sorry, but I'm not seeing anything called player controller, when I search through the Starter Assets.
@sobean7699
@sobean7699 Жыл бұрын
I have an issue where if I add the "direction" part to my raycast I already have set up, it shoots the bullets into the sky instead of going forward
@agito0207
@agito0207 2 жыл бұрын
Thanks this helped a lot. Only issue I can't seem to resolve is the bullet impact decal. It will only show on walls facing worlds Z direction. If I shoot walls in the X direction the decal won't show because the rotation of the impact effect scales the decal. Kant seem to figure out how to resolve this.
@LlamAcademy
@LlamAcademy 2 жыл бұрын
Hey! Make sure you are setting the rotation of the impact particle system / decal to be based on the hit.normal. If you are setting it like at 08:10 then it should be pointing directly out from the hit normal direction.
@agito0207
@agito0207 2 жыл бұрын
@@LlamAcademy Ok I tried the GitHub example from the video. When using your set-up I get the same result. Particles is rotated correctly. But if it gets rotated on the Y axis the decal gets scaled down. So it is no longer visible. (so everything rotates correctly except the child decal) All I changed in that project was upgrade to URP.
@luisjoia9744
@luisjoia9744 2 жыл бұрын
how do i add bullet trail when i shoot the skybox? this method only returns when I hit a collider else bullet trail is invisible
@LlamAcademy
@LlamAcademy 2 жыл бұрын
Great question! I totally didn't mention that this requires a raycast hit in order to shoot. I was imagining scene setups that have bounds in some direction. For example a collider 100 units up as the invisible ceiling above the level. Your shots will then hit this if they miss everything else. A second option that does not require scene bounds could be, If nothing is hit, choose a point in that direction, let's choose 100 units again, and use that as the "hit point" and do the exact same thing. That should be as simple as taking the start position and adding in the raycast direction multiplied by 100.
@luisjoia9744
@luisjoia9744 2 жыл бұрын
@@LlamAcademy Well that worked like a charm, definitely helping my game dev dream become a reality
@LlamAcademy
@LlamAcademy 2 жыл бұрын
For that scenario, you can update the SpawnTrail to accept a Vector3 instead of a RaycastHit. Then for the case where you DO hit something, you pass in the hit.point for the second argument of SpawnTrail. For the case where you DO NOT hit something, you can simply pass in BulletSpawnPoint + direction * 100
@LlamAcademy
@LlamAcademy 2 жыл бұрын
@@doobyredwizard when the Physics.Raycast returns false, you know you did not hit anything. That's when you'd "fake" the hit 100m away
@devioxs5355
@devioxs5355 2 жыл бұрын
Could anyone tell me how I could add shrapnel to explosions with object penetration also nice video
@monahajt
@monahajt 2 жыл бұрын
Can you explain what the purpose of the Animator was, and what that is achieving?
@LlamAcademy
@LlamAcademy 2 жыл бұрын
The Animator was to just get that spinning effect on the Minigun. It seems like it needs a little more work because it doesn't always animate properly 😅
@monahajt
@monahajt 2 жыл бұрын
@@LlamAcademy Okay thank you! that makes more sense
@anonymoussloth6687
@anonymoussloth6687 2 жыл бұрын
Can you elaborate on the part where the bullet hits something that moves fast and isn't there anymore? I am still confused how we would solve that Also, how can we implement wallbanging like in valorant or other famous games?
@LlamAcademy
@LlamAcademy 2 жыл бұрын
Hi. There are several options for the fast moving object hits, it depends on how you want to handle it in your game. You can ignore particularly fast moving objects by having those on their own layer. You can make the bullet follow the object it hit, so it won't go in a straight line but the impact location will be at the hit point on that particular object, or you could even have the tracer go to the initial hit point and have the bullet impact play at the hit point on the object that was hit! Regarding bouncing bullets, I have a video and it's linked in the description for that: kzbin.info/www/bejne/fZy2pYpuYrZohpI
@S0APS_
@S0APS_ Жыл бұрын
I actually just created a pretty cool method that does the kind of wall banging as whats seen in R6S. It still has some tweaks and configuration for seperate guns but the idea is that you create a mesh and when a raycast interacts with one of the triangles of the mesh by checking with a mesh collider that triangle and the surrounding ones are deleted. It works really well. Only issue is I am not sure how it will hold up in a large map where all the walls are able to be shot up. Might have to work on optimization.
@sohodollie7643
@sohodollie7643 Жыл бұрын
This is really cool but i'm getting into a bit of an issue. Because the trail moves from the the muzzle to hit.point, if the raycast misses and doesn't shoot anything, the trail renderer doesn't activate. This can create some really weird behaviors, for example if you are shooting at someone and 50% of your shots miss, only 50% of your shots would generate trails. In your example they always generate trails because they always hit something like the wall for example. Any ideas for getting around this? I initially thought about just increasing the range of my raycasts by a huge distance and setting up invisible walls all around my scene to catch any stray bullets, but this doesn't really seem like an optimal solution. Any feedback appreciated!
@LlamAcademy
@LlamAcademy Жыл бұрын
Yes, that is a great point. I think so far 2 main issues have been identified in this tutorial. I have addressed both of those in the GitHub repository if you are simply looking for a copy/paste solution. If you want to understand how it works, please check out the pinned comment for the tutorial where I implement similar functionality + bouncing, without the 2 issues the community has helped identify with this solution.
@sohodollie7643
@sohodollie7643 Жыл бұрын
@@LlamAcademy Thanks! The bouncing video was great and solved the issues I was facing. I understand maybe 80% of it, so I'm going to reread the code and read some documentation to figure it out :] but appreciate the solutiom
@karacter3369
@karacter3369 11 ай бұрын
Maybe pass camera.transform.foward instead of a hitpoint (when miss == true)
@RealJares
@RealJares Жыл бұрын
please help me my hot trail effect is shooting sideways for some reason
@LlamAcademy
@LlamAcademy Жыл бұрын
I recommend to check out the code from GitHub to see what you have different from what is implemented there. On GitHub it also has some small fixes to what was implemented here from the community
@RealJares
@RealJares Жыл бұрын
Thanks for the feedback! Will try that in a second
@WizardMonke
@WizardMonke 2 жыл бұрын
Hey there, good vid. I do have one problem though. For some reason the bullet trail bends when it's lerping to the endpoint. The way I have my shooting set up is that the shooting raycast technically comes from the center of the screen, to make sure it's always hitting where the player is looking (right through the crosshairs), but the trail comes from the barrel of the gun. However, when I shoot, for some reason the bullet sometimes bends off-course.
@LlamAcademy
@LlamAcademy 2 жыл бұрын
Hi! That's hard to say what's going on from just that description. As long as you're using the trail renderer moving code here and providing the start location of the tip of the gun, and end point of the hit point for the raycast hit, there shouldn't be any problem since we're just moving from point A to point B
@WizardMonke
@WizardMonke 2 жыл бұрын
@@LlamAcademy Yeah that's why I'm struggling to figure this out lol. If I start the scene and just shoot forward, without rotating or moving, the bullet tracer moves properly. If I rotate the player left or right, then the trail starts bending before it gets to the target. GIF Example: 1drv.ms/u/s!An5X8q8AyS6BgcYxfR09EUPFN1stTg?e=ana086
@WizardMonke
@WizardMonke 2 жыл бұрын
@@LlamAcademy Fixed it! Turns out the problem was that the width of my trail renderer wasn't changing. Thought it was a physics problem the whole time, so no wonder I was confused!
@LlamAcademy
@LlamAcademy 2 жыл бұрын
Awesome! Glad you figured it out
@gDevGuy001
@gDevGuy001 Жыл бұрын
the materials of the particle assets pack does not working showing Pink material.....does anyone have any solution
@n3onf0x
@n3onf0x Жыл бұрын
Is there an alternative that doesn't use Player Input?
@LlamAcademy
@LlamAcademy Жыл бұрын
Sure, you can use the old input system with Input.GetKey or GetKeyUp: docs.unity3d.com/ScriptReference/Input.GetKey.html
@XXIstCenturyBoy
@XXIstCenturyBoy 2 жыл бұрын
Every times I see that "you, yes you" intro I am not sure what is happening...
@LlamAcademy
@LlamAcademy 2 жыл бұрын
you're getting another step closer to making your game dev dream become a reality of course! 😊
@AZASeraph
@AZASeraph 2 жыл бұрын
What if I'm using my own rigid body script
@LlamAcademy
@LlamAcademy 2 жыл бұрын
Then this one would help you out! kzbin.info/www/bejne/labNlnueq7SfkLc For the simple case you can just attach a trail renderer to the bullet and configure it so it looks nice.
@AZASeraph
@AZASeraph 2 жыл бұрын
@@LlamAcademy ok thanks, I watched the video and was wondering bc at the start you setup the new action and I couldn't do that
@LlamAcademy
@LlamAcademy 2 жыл бұрын
Yeah, that was just to use the new input system to shoot. If you are using the old input system, on that PlayerAction class on Update you can do something like if (Input.GetKeyUp(KeyCode.Mouse0)) { ...the shooting code here } to get the same result
@AZASeraph
@AZASeraph 2 жыл бұрын
@@LlamAcademy ok thanks so much, this was one of the few videos that actually did this and it looked good as I wanted to use rigudbodies instead of raycasts so the player can see the bullets Edit: also would I need to do OnButtonDown so that it shoots when they player presses down?
@LlamAcademy
@LlamAcademy 2 жыл бұрын
It's just Input.GetKey if you want them to be able to press and hold docs.unity3d.com/ScriptReference/Input.GetKey.html
@jcmartinez.8782
@jcmartinez.8782 Жыл бұрын
How did you solve the problem of shooting moving objects?
@LlamAcademy
@LlamAcademy Жыл бұрын
I think the simplest solution is to parent the decal and impact particle system under the hit object using transform.SetParent passing true for the second argument
@jcmartinez.8782
@jcmartinez.8782 Жыл бұрын
@@LlamAcademy It's hard when the object you're shooting at is at a long distance.
@LlamAcademy
@LlamAcademy Жыл бұрын
Oh, sorry I thought you were talking about the bullet impact. There are 2 relatively straightforward ways to solve the hit/miss problem for quickly moving objects. There are always more, but these I think suit most use cases. First one is simple, make the bullet move more quickly. The faster the bullet trail, the less likely this is noticeable. For example in Battlefield V, the tracer is only generally visible for 1-5 frames. Very difficult to tell other than the impact and the UI hit indicator that you hit/missed. Second one is more complex. You can do a raycast between the positions of the trail every frame and see if you hit something. This will allow you to determine if something else obstructed the path while showing the trail and allow you to hit that instead. Also, if the target moved too far out of the way, you can identify that and count it as a miss.
@artdays9561
@artdays9561 2 жыл бұрын
So I have a drop and pickup system in my game, and whenever I click on my mouse, my gun shoots, so how do i make it so it only shoots when I am holding the gun?
@LlamAcademy
@LlamAcademy 2 жыл бұрын
You can disable/enable the script for shooting based on if the player has picked up a gun, or add a condition to the Gun script to check something like if (IsHeld) { Gun.Shoot(); }
@yaboycj
@yaboycj Жыл бұрын
Looking up and down with my camera and shooting still shoots the trail forward, not where im looking, why is this?
@LlamAcademy
@LlamAcademy Жыл бұрын
In this video we are raycasting from the tip of the gun in the direction of the gun's forward. We didn't implement rotating the gun based on the camera's look rotation which would be required to make the gun shoot up/down where you are looking.
@yaboycj
@yaboycj Жыл бұрын
@@LlamAcademy how would i go about doing this in that case?
@yaboycj
@yaboycj Жыл бұрын
Nevermind, fixed it, in direction, instead of just putting transform.forward, i did cam.transform.forward, thanks for the awesome tutorial anyways!
@LlamAcademy
@LlamAcademy Жыл бұрын
Glad you got it sorted!
@nileshkumawat2997
@nileshkumawat2997 2 жыл бұрын
Why you are not using object pool?😅
@LlamAcademy
@LlamAcademy 2 жыл бұрын
Sometimes it's simpler to show the concept without introducing too much extra stuff 🙂 I generally recommend to use an Object Pool for anything like this
@BroxExe
@BroxExe 2 жыл бұрын
how i can change shoting rotation (its shoting in wrong way)
@LlamAcademy
@LlamAcademy 2 жыл бұрын
Hi! What do you mean it's shooting the wrong way?
@graystandards
@graystandards Жыл бұрын
SerializeFeild wasn’t a thing in my unity
@LlamAcademy
@LlamAcademy Жыл бұрын
SerializeField has been around under UnityEngine namespace for almost ever. In your comment it’s a typo, so hopefully you just have that same typo in the code!
@graystandards
@graystandards Жыл бұрын
@@LlamAcademy ooooh ok sorry thanks
@krabbyPatty824
@krabbyPatty824 Жыл бұрын
8:34 bookmark
@Joot_Joot
@Joot_Joot Жыл бұрын
goofy ahh intro
@LlamAcademy
@LlamAcademy Жыл бұрын
It’s my favorite part of every video 😊
@ty-xq7bl
@ty-xq7bl Жыл бұрын
handsome!
@LlamAcademy
@LlamAcademy Жыл бұрын
Thanks!
@taratraptaratrap8394
@taratraptaratrap8394 2 жыл бұрын
How to make in work if you hit the sky
@LlamAcademy
@LlamAcademy 2 жыл бұрын
Please check the pinned comment!
@taratraptaratrap8394
@taratraptaratrap8394 2 жыл бұрын
@@LlamAcademy I've solved the problem: If not raycast hit, then create a trail from start position to 1000 meters forward, it works fine
@tamamlanmamis
@tamamlanmamis Жыл бұрын
I found a weird bug. When the ray cast doesnt hit anything the bullet trail goes to a random direction. Can someone help?
@sameerfaridi2
@sameerfaridi2 Жыл бұрын
it is too advance for me 😢😢
@Crowbar
@Crowbar 2 жыл бұрын
The video is called "Add Bullet Tracers to Your Hitscan Guns", but most of the video has nothing to do with that...
@LlamAcademy
@LlamAcademy 2 жыл бұрын
I can agree to a point with that. This video shows both implementing a basic hitscan gun, and tying in the bullet tracers. If the video was explicitly only about adding bullet tracers, it leaves out too much context for less experienced developers. That's part of why I include the chapters: so you can jump around to the parts you feel are most relevant to you
@sobean7699
@sobean7699 Жыл бұрын
In the trail render section where it goes TrailRenderer trail = Instantiate(BulletTrail, bulletSpawnPoint.position, Quaternion.identity); StartCoroutine(SpawnTrail(trail, hit)); It keeps giving me an error on SpawnTrail and says that its not defined
Bouncing Bullets with Hitscan Guns | Unity Tutorial
14:14
LlamAcademy
Рет қаралды 14 М.
兔子姐姐最终逃走了吗?#小丑#兔子警官#家庭
00:58
小蚂蚁和小宇宙
Рет қаралды 14 МЛН
🕊️Valera🕊️
00:34
DO$HIK
Рет қаралды 18 МЛН
Wait for it 😂
00:19
ILYA BORZOV
Рет қаралды 10 МЛН
Wait for the last one 🤣🤣 #shorts #minecraft
00:28
Cosmo Guy
Рет қаралды 20 МЛН
20 Advanced Coding Tips For Big Unity Projects
22:23
Tesseract
Рет қаралды 195 М.
Unity VFX Graph - Muzzle Flash Effect Tutorial
14:30
Gabriel Aguiar Prod.
Рет қаралды 144 М.
When Your Game Is Bad But Your Optimisation Is Genius
8:52
Vercidium
Рет қаралды 1,5 МЛН
AI Learns to Play Tag (and breaks the game)
10:29
AI Warehouse
Рет қаралды 4,1 МЛН
I Remade Avatar Water VFX in 100 Hours
11:38
ErikDoesVFX
Рет қаралды 37 М.
Unlocking The Power Of Unity's Scriptable Render Pipeline
21:05
Game Dev Guide
Рет қаралды 217 М.
SHOOTING with BULLETS + CUSTOM PROJECTILES || Unity 3D Tutorial (#1)
9:25
Dave / GameDevelopment
Рет қаралды 203 М.
How do non-euclidean games work? | Bitwise
14:19
DigiDigger
Рет қаралды 2,4 МЛН
兔子姐姐最终逃走了吗?#小丑#兔子警官#家庭
00:58
小蚂蚁和小宇宙
Рет қаралды 14 МЛН