Тёмный

[#05] Shooting a weapon using Projectile Raycasts (with effects) 

TheKiwiCoder
Подписаться 17 тыс.
Просмотров 86 тыс.
50% 1

This video demonstrates how to add weapon effects such as muzzle flash, bullet tracers, and impact effects. The weapon has tweakable bullet velocity, bullet drop, and fire rate. Everything is done using 'projectile raycasts' to simulate projectile motion without using a rigid body.
► Next Video: • [#06] Weapon pickups: ...
► Previous Video: • [#04] Unity Animation ...
Assets used in this video:
► Unity Particle Pack: assetstore.unity.com/packages...
► Polygon Sci-Fi City Pack: assetstore.unity.com/packages...
** Share this video **
• [#05] Shooting a weapo...
**********************
** Subscribe **
/ @thekiwicoder
***********************
Follow Me:
► / thekiwicoder
► / thekiwicoder
Thank you!

Кино

Опубликовано:

 

16 май 2020

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 389   
@TheKiwiCoder
@TheKiwiCoder 3 года назад
UPDATE: Hi all, there is a small bug in the CrossHairTarget script which will cause the gun to fire backwards. Convert lines 22/23 to this: if (Physics.Raycast(ray, out hitInfo)) { transform.position = hitInfo.point; } else { transform.position = ray.origin + ray.direction * 1000.0f; }
@gevonstria
@gevonstria 3 года назад
Thank you, silly of me not checking the comments before being stressed out by this bug. Thank you for this great tutorial!
@awiseauthor3456
@awiseauthor3456 3 года назад
@@rosegarrote9666 in a later video he said that he's going to
@uzumakilol1288
@uzumakilol1288 3 года назад
I had to rewrite the whole thing, still appeared came to check and saw this comment
@bernie_san7964
@bernie_san7964 3 года назад
all i did was flip the Y position of the raycastOrigin in the inspector and that was simple enough lol
@d4ngerous143
@d4ngerous143 3 года назад
This made me bug even more lol
@roarlisfang2860
@roarlisfang2860 3 года назад
This video deserves more view, literally hand to hand tutorial.
@TheKiwiCoder
@TheKiwiCoder 3 года назад
Thank you 😊
@aciem
@aciem 3 года назад
For those people who have a character close to camera, consider to use layers or tags to ignore the player on raycasts, or every ray cast will be absolute messy. Kiwicoder has a character far from the center of the cam, however, he can face problems when the cam is moving closer to character in some situations like when cam avoid clipping. PD: great tutorials dude (clap!, clap!, clap!)
@eugenepark6787
@eugenepark6787 4 года назад
You are the legend. Honestly, one of the best tutorial channel. The explanations are so clear. Absolutely deserve a lot of subscribers but for now just one more by me :)
@TheKiwiCoder
@TheKiwiCoder 4 года назад
Thank you! ✌️
@Bamboozled007
@Bamboozled007 3 года назад
Man just wanted to say this series is awesome! Thanks for taking the time to explain all this, it helps SO MUCH!
@geniusrealms
@geniusrealms 2 года назад
I know this is coming late from me. But I'd you're seeing this comment I just wanna thank you for how your tutorial have changed my Game Dev Journey
@code_guru5110
@code_guru5110 2 года назад
Best Unity shooter tutorial made EVER! YOU ROCK SIR
@Krafter37
@Krafter37 4 года назад
Thank you so much for this tutorial ! I had some troubles as the particles of the pack were different for me, with other settings. But I changed my projectile based shooting system to a hitscan one after seeing your tuto and it fix a lot of issues that I had. I'll just need to watch the 2nd part of the video now to implement some velocity and drop :) Thanks again !
@TheKiwiCoder
@TheKiwiCoder 4 года назад
You’re very welcome! Good luck!
@bymehmetyildiz
@bymehmetyildiz Год назад
For the ones who has a computer freeze after running game, it is happening because of the while loop. Change while( accumulatedTime >= 0) to while( accumulatedTime >= fireInterval). Fixed.
@Morphinias
@Morphinias 3 года назад
This tutorial solved my biggest game maker problem. Thanks a lot!
@theDarkerSan
@theDarkerSan 2 года назад
That's the best way to instantiate a hit effect I can imagine! You are a legend!
@Hyphen3372
@Hyphen3372 3 года назад
Amazing dude keep up the good work btw thnx for the tutorial series. i have only done game dev for 5 month now and i couldnt really understud c# or programing and i just kept researching and i saw your chanell and i kept following until i finished the series and i looked back at the code and i slowly understud how c# and programing works and then i changed it to an fps and im having with trying to make a game of my so thank you kiwi coder keep up the good work.
@Deaker24
@Deaker24 3 года назад
Another kiwi I've just started really getting into unity it's good to see another kiwi.
@subhendumukherjee4722
@subhendumukherjee4722 2 года назад
A super tutorial with wanderful explanation.
@rwells242
@rwells242 2 года назад
Thank you so much for this tutorial. Especially the final section
@f4lllegion607
@f4lllegion607 3 года назад
Fantastic Video! Extremely well taught, easy to understand, and pleasant to listen to. Thank you so much, this helped a ton! :D
@diliupg
@diliupg 3 года назад
I just finished this video. Your videos on this topic so far have been the best ever on RU-vid. Your detailed explanation of the complex content puts some courses on Udemy to shame. If you do a course on Udem, I will be one of the first to buy it. Great content!.
@leosalazar9213
@leosalazar9213 2 года назад
You are a Beast man
@USBEN.
@USBEN. 2 года назад
I made a actual pooled projectile spawn system. But i needed something like this and didn't know trail renderer was a thing. Thank you hahaha.
@spgames9648
@spgames9648 3 года назад
Thanks you very much for your tutorial on raycast ! For my video game, I don't need the "bullet drop" part, but until that, it's was interesting !
@Tommy23r10
@Tommy23r10 Год назад
Still fantastic, much appreciated mate!
@m-horth2187
@m-horth2187 2 года назад
Excellent tutorial! I'm amazed at how much the muzzle flash and hit effects add to the realism. I checked a bunch of other comments to see if you had answered this question, so hopefully I'm not making you repeat something. How do you handle raycasting at objects that are really close to the player? I'm using a very similar raycast system from the center of the screen and making my bullets travel from the tip of the gun towards my aim target. If I walk up to an object so that I'm basically touching it, it become very obvious that bullets are shooting almost sideways out of the gun.
@VannaraHor99
@VannaraHor99 3 года назад
Thank you much , Your video is best experience to me.
@ohalohuntero
@ohalohuntero 3 года назад
Super awesome tutorial once again. took me all day but I got it all working lol. As a request it would be cool to see a state based character controller for like running jumping climbing ladders or walls etc later. or some tutorials on how to equip stuff to your character from like a shop (clothing items/armour etc). Thanks again!
@TheKiwiCoder
@TheKiwiCoder 3 года назад
Thanks for the feedback!
@x-lufias69
@x-lufias69 2 года назад
thanks for the last part. I wasted 2 days finding and thinking how to perform that. although I didn't understand most of the codes for making a lot of functions but things are working for me and I can make the work done by that :D
@TheKiwiCoder
@TheKiwiCoder 2 года назад
Woop woop 🙌
@RainDevs
@RainDevs 3 года назад
These tutorials are just beautiful. Please create a patron so I can support you a bit. :)
@TheKiwiCoder
@TheKiwiCoder 3 года назад
Hey Chase! If you'd like to support the channel you can find my Patreon here: www.patreon.com/thekiwicoder Thanks!
@mooumari8210
@mooumari8210 3 года назад
Amazing content keep going
@marekpuchon4878
@marekpuchon4878 Год назад
Amazing stuff!!! Golden guy this TheKiwiCoder!!!
@mohamedmusthafa1057
@mohamedmusthafa1057 Год назад
You can also Calculate the Screen Width and Hight / 2 and make Target Center
@omerfi
@omerfi 3 года назад
If anyone cannot see the red line (created by Debug.DrawLine), make sure to enable gizmos
@TheKiwiCoder
@TheKiwiCoder 3 года назад
Thanks for the tip!
@nikhstudiosthe1
@nikhstudiosthe1 2 года назад
but I still cannot see the red line
@rahulmaramreddy4853
@rahulmaramreddy4853 11 месяцев назад
@@nikhstudiosthe1 For those still having issues, make sure you are adding Gizmos to the scene you are actually looking at! If you add the Gizmos in the "Game" scene, look there!
@Deaker24
@Deaker24 3 года назад
Since you seem very knowledgeable
@a.technology1446
@a.technology1446 4 года назад
Amazing ❤️
@elsyndur4415
@elsyndur4415 3 года назад
Very nice!
@Runix1
@Runix1 2 года назад
Absolutely love this solution, and the steps were really well explained! I do have one question, about the ray section function. You make a raycast from the start point, in the direction of and distance to the end point. Are there any advantages to this, compared to a linecast from start to end?
@tweenky
@tweenky Год назад
cool beans, thanks
@NorbertCsecs
@NorbertCsecs 3 года назад
Best, massive lifesaver
@adinafshar4117
@adinafshar4117 Год назад
amazing thanks for video 😍😍😍
@raimanchannel3376
@raimanchannel3376 Год назад
Amazing video !!! =)) Thanks
@choucheneyoussef3281
@choucheneyoussef3281 3 года назад
i couldnt make the material of the trail cuz i didnt find the same values to change can u upload the material ? i mean the material of the bullet tracer thanks for the tutorial it was helpful
@danthonyhill9906
@danthonyhill9906 4 года назад
Great tutorial love it you did it again !! Will you be doing a weapon switch ?? From rifle to pistol for example and maybe ammo counter maybe
@TheKiwiCoder
@TheKiwiCoder 4 года назад
Thanks! Yeah I'd like to cover that. Handling different weapons easily and attaching them at runtime :)
@danthonyhill9906
@danthonyhill9906 4 года назад
TheKiwiCoder You welcome mean anytime 👌🏿👌🏿💪🏿💪🏿💯💯
@kingofgranges
@kingofgranges 3 года назад
Amazing job man! This playlist is gold 👍🏼
@ericbramble5043
@ericbramble5043 2 года назад
@TheKiwiCoder Hey man, having a small issue. If I move my character little by little the animation pose becomes warped until my normal holding the gun pose looks like broken wrists and physics from a world Doctor Strange frequents. It starts off behaving perfectly, but maybe bleeding kinematics causing pose warping? (The subtle inaccuracies adding up over hundreds of tiny movements until the referenced transforms resemble nothing of the initial values) I'm not sure but I'm at a loss. Did you or anyone else here experience anything like this?
@rafarodriguez4765
@rafarodriguez4765 3 года назад
Firstly a huge congrats! It is the best Raycast shoot tutorial I have seen. I am surprised by the so advanced level. How many years are you programming C#?
@TheKiwiCoder
@TheKiwiCoder 3 года назад
Thanks man, I graduated in 2008. So a while now 😅
@mohamedmusthafa1057
@mohamedmusthafa1057 Год назад
Dude But why U making Everything public instead [SerializeField]
@paradisekid2k
@paradisekid2k 11 месяцев назад
For those who are having white boxes in URP with the hiteffect particle, change the Dust shader to URP/Particles/Simple Lit
@snakeplisken4278
@snakeplisken4278 3 года назад
Very nice. How about sound effects and shells dropping on the floor?
@TheKiwiCoder
@TheKiwiCoder 3 года назад
Man yes, sound effects I really want to add.
@jaywilliams9721
@jaywilliams9721 3 года назад
Another kiwi? Great tut by the way
@saurya_jhbvbiuh
@saurya_jhbvbiuh 3 года назад
how would i make it to where the tracer shows up even when i shoot in the air
@adarshkaran6611
@adarshkaran6611 3 года назад
You da best🔥
@cryptic1008
@cryptic1008 4 месяца назад
For now im just copying for my uni project but i will be back to learnd this from the start
@collective_420
@collective_420 Год назад
I would like to know if it is possible in any way to apply a particle system to the bullet as well?
@bishoyfahim2266
@bishoyfahim2266 2 года назад
what do i have to change in the code to use projetiles(bullet prefabs) instead of the trail render?
@spideyman1909
@spideyman1909 3 года назад
it says rig could not be found when I make it a pub variable and its not used in the script?
@Meowzors
@Meowzors 4 года назад
How would you implement an aim zoom that zooms in on the crosshair? I tried changing the field of view, but it just focuses on my look at target.
@TheKiwiCoder
@TheKiwiCoder 4 года назад
I would change a combination of FOV and zoffset. Another thing to experiment with is creating a separate dedicated camera and blend between them using cinemachine
@awiseauthor3456
@awiseauthor3456 3 года назад
He made a new video that goes over this topic exactly, if you still haven't figured it out.
@Krafter37
@Krafter37 2 года назад
I just noticed that for me the particle (when I increase their size to shoot "spheres") appears flat instead of spherical, any idea how to fix this ?
@agerausten6630
@agerausten6630 3 года назад
Hey man !!! You are super
@elyeskabous2343
@elyeskabous2343 2 года назад
Thank you boss
@gohelboy
@gohelboy 4 года назад
I love this tutorial but after the 25 min it getting. Confusion for begginer like me and others so please explain everything thank you
@MattForemanFlow
@MattForemanFlow 8 месяцев назад
This is awesome! Thank you so much. I am trying to make an "energy cannon" style weapon that shoots a decent-sized "energy ball" projectile at a slower speed than a bullet would travel. The methods you used seem like they should work for this use-case! Originally I was going to use a rigidbody with a sphere collider and Unity's physics system to calculate travel & hit detection, but I read that this may be performance heavy and a raycast-based projectile is more optimized. I particularly like the equation-based (deterministic) positioning of the bullet based on time. Some questions for you: 1. Why did you use 'LateUpdate' to calculate bullet travel rather than 'Update' or 'FixedUpdate'? I trust that this works, but it wasn't explained in the video. 2. Would it be "wrong" to use 'FixedUpdate' for calculating bullet travel/impact? And what are the implications of doing so? (For example, poor performance?) For #2 I understand that using 'Update' or 'LateUpdate' would always provide smooth visual movement of the bullet (since 'FixedUpdate' time may not always line up with the 'Update' loop, causing jitter). However, I'm second guessing myself because isn't 'FixedUpdate' the right thing to use if we're doing a physics calculation such as a bullet hitting a wall? If we used 'LateUpdate' then wouldn't the accuracy of bullet impact calculations differ based on each player's framerate, putting lower-spec players at a disadvantage? Could a combination of both be used - 'FixedUpdate' for hit detection and 'LateUpdate' for the visual? Or does it actually not matter that much and I am overthinking it? For a competitive multiplayer game I just want to make sure things are accurate *enough*, even if 'LateUpdate' is used.
@TheKiwiCoder
@TheKiwiCoder 8 месяцев назад
It’s been a while since I made this but I think I used late update to ensure animation rigging had run and the muzzle position was up to date when spawning the bullet. But you’re right though fixed update sounds better for simulation and use late update for the visuals. For a multiplayer game though you might be running the hit detection on the server which is untied to the clients frame rate.
@brunoloverius5777
@brunoloverius5777 3 года назад
Hello man! I did follow your tutorial but i can't manage to get my material right for the bullet tacer. It's invisible for me. I do see the fact that it's there whe i select it in my inspector. Have you ever had such an issue? great tutorial btw :)
@TheKiwiCoder
@TheKiwiCoder 3 года назад
Thanks :) check which shader it’s using on the material.. also post this in the discord, it’s a bit easier to help there.
@MajorParts
@MajorParts 3 года назад
Make sure you didn't accidently apply a Line Renderer, like I did :D
@drr1867
@drr1867 4 года назад
Brilliant video - again! How do I change the rotation of the gun at this point? It's not quite pointing at the target dot when I aim. I can't find a way of doing it now everything is hooked up. Thanks
@TheKiwiCoder
@TheKiwiCoder 4 года назад
Hey, the multi aim constraint should be pointing the gun at the dot. Bring the AimLookAt game object in/out from the camera to change the angle.
@drr1867
@drr1867 4 года назад
@@TheKiwiCoder Thanks for that but it doesn't seem to do much. I'd like to change the position of the gun in the hands but now the aiming system is working I can't do it when in play mode as I can't aim and adjust settings at the same time. I can't temporarily turn off things either so I can reposition my gun and hands. When in play mode I can't see my gun as it's behind the player - I'd like to move it if possible. Any thoughts would be welcome -thanks again - brilliant tutorials
@TheKiwiCoder
@TheKiwiCoder 4 года назад
Ah ok, what you can do is rather than aiming the weapon, create a weapon holder object, and add the weapon as a child of that. Attach a rig constraint to it which you can then position. It’s explained a bit more in this video: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-bIOxl8iDWoU.html
@drr1867
@drr1867 4 года назад
@@TheKiwiCoder Awesome - thank you so much - I'll have a look. Can't wait for more of your tutorials - you are the best on RU-vid.
@tianqigao869
@tianqigao869 Год назад
Excellent tutorial! I learned a lot from it. Thank you! At 3:28, I noticed you put the input processing code in the LateUpdate method instead of Update method. Are there any good reasons to do that, why not just put the code in Update method?
@TheKiwiCoder
@TheKiwiCoder Год назад
No, input should be processed as early in the frame as possible. I was probably fighting against a cinemachine update ordering issue with animation rigging
@xdxdxd6599
@xdxdxd6599 2 года назад
awesome tutorial! but I have a bit of a problem, when I add the bullet tracer and start playing it, the startpoint of the bullet tracer is too slow to catch up the gun point and after a few moment it catches up. How can I make this faster?
@TheKiwiCoder
@TheKiwiCoder 2 года назад
I haven’t tried this myself, but you could try running the bullet code inside late update. Interested to know if this works!
@christopherkurzak5187
@christopherkurzak5187 2 года назад
Very kool!
@danielbohme5690
@danielbohme5690 3 года назад
How would you make an object pool out of the bullets? This instantiates and destroys objects constantly which isn't optimal. I am having some issues with trying to modify your script to be able to use object pooling
@TheKiwiCoder
@TheKiwiCoder 3 года назад
This might help: docs.unity3d.com/2021.1/Documentation/ScriptReference/Pool.ObjectPool_1.html Replace new Bullet with pool.Get(), and call pool.Release() on the bullet before removing it from the list.
@HimKnot
@HimKnot 2 года назад
I don't have RaycastWeapon Edit: got it to work. I just don't know how to delete all the instantiated objects Edit2: nevermind, I just didn't see the tutorial fully. Ok now I got everything to work. Thank you for the tutorial :D
@castlecodersltd
@castlecodersltd 9 месяцев назад
This is a great video. I found that I had to test that bullet.tracer wasn't null in RaycastSegment. Weirdly the video stutters for me. 1080p60. No other makers videos do. Strange. Doesn't take away from the video though. Thanks ☺
@ernstplayzgd8015
@ernstplayzgd8015 3 года назад
Hey when i go fullscreen my particles just disappear i dont know what to do here someone have a fix?
@Brightfield
@Brightfield 3 года назад
Hey @TheKiwiCoder! I was just wondering, do your bullets also persist (dont get destroyed) when you aim and fire at horizon? I notice in the code that the maxLifetime of the bullet is only set OnHit, but not in the else statement. Awesome tutorial vids my man! Keep it up!
@yinmonk23
@yinmonk23 4 года назад
great !!!!!
@aurel2884
@aurel2884 3 года назад
I need to install wich package for having the Universal render pipeline particle ?
@awiseauthor3456
@awiseauthor3456 3 года назад
If the textures on the effects show up (the MuzzleFlash01, for example, will be orange/red) you can skip that step.
@Crekpozer
@Crekpozer 3 года назад
Hello, i'm follow the tutorial but i have a problem: My bullets is stoping in the mid air after some distance, how lower is the bullet speed the closer is the distance that the bullet stops, the bullets keeps going back and forward until hit something, like the character. sorry for my english, but i realy needs help.
@robertli8008
@robertli8008 4 года назад
The last part of the video (the part where you mostly do the scripting for bullet drop and bullet simulation) is kinda confusing and you went over it super quickly. It would be helpful to have like a conclusion or an overview of what you were doing (something like a drawing or illustration that explains the logic behind the script). That's just my two cents.
@DJLKM1
@DJLKM1 4 года назад
Gold again :)
@kieranraquel2949
@kieranraquel2949 3 года назад
Hey man! I have been following your tutorial. But I have to ask about the CrossHairTarget script. I followed the exact steps you say and all of a sudden my CrossHairTarget just aims at my player's shoulder. Basically, It acts as more as person with a camera than an actual target base. Is there anything around it?
@TheKiwiCoder
@TheKiwiCoder 3 года назад
I pinned a comment with a small fix to that script, check if that helps.
@kieranraquel2949
@kieranraquel2949 3 года назад
@@TheKiwiCoder It didn't help, It was still shooting backwards though. I tried changing the setting the camera setting or the cinemachine settings but it didn't help as well. Edit: Ok! I found the reason CrossHairTarget is colliding against my character but I don't know how to get around it. Even with your updated code. Update Edit: I solved the Problem. It was the skin mesh Renderer that messes me up. So yeah! To all the people who have trouble with the weapon shooting backwards. Either Just adjust the code that has been pinned by TheKiwiCoder and/or Adjust the Skin Mesh Renderer. Cheers!
@goblinslayer07
@goblinslayer07 2 года назад
Hey, Loving the tutorial but I'm having an issue. if I use the DestroyBullets function with => I will get an error in the console after shooting for a while stating that "The object of type 'TrailRenderer' has been destroyed but you are still trying to access it." However, if I change it to match the prompt on screen at 41:00 to use >= instead then I get the error "The name 'bullet' does not exist in the current context". Any ideas?
@TheKiwiCoder
@TheKiwiCoder 2 года назад
Ah yes the prompt text wasn’t very clear. Change the ‘>’ to ‘>=‘. The second operator. The first should be left as =>. Apologies for the confusion
@chrishaynes4355
@chrishaynes4355 2 года назад
@@TheKiwiCoder I tried the correct way but I am still getting The object of type 'TrailRenderer' has been destroyed but you are still trying to access it.
@nikhstudiosthe1
@nikhstudiosthe1 2 года назад
hey in the ray cast wepon script even when I am clicking the left mouse button it is not changing the is firing to true if some can help me out please
@sere789654
@sere789654 2 года назад
I have been having problems with the bullets instantiating the decal part of the hit effect. I noticed the decal part didnt have a particle so I tried adding. Seems my problem may be it is destroying the main prefab in the weapon.
@wesleye9062
@wesleye9062 Год назад
I am having the same problem
4 года назад
Thanks for the great tutorial. I am learning so much with your videos. You are really awesome. I noticed an issue with the fire rate and have not found a solution to that yet. If i click as fast as i can, i am able to ignore the fire rate of the gun. This is easier to spot when the fire rate is set to a low value (e.g. 5). It has to do with resetting accumulatedTime and FireBullet() in StartFiring(). Since i removed both those line from StartFiring() function i am not able to fire faster than the fire rate, but also some manual shots get ignored because the accumulated time is never reset.
@TheKiwiCoder
@TheKiwiCoder 4 года назад
You're welcome! Thanks for spotting that. To fix it: accumulatedTime should be updated even when not firing, so move it into UpdateBullets for example. Then inside StartFiring, check that it is greater than zero before resetting (if it is negative, it's still in the cooldown period).
4 года назад
@@TheKiwiCoder Your suggestion works like a charm. Thanks!
@danielruss5022
@danielruss5022 3 года назад
@ @TheKiwiCoder how exactly would this look like ? if(accumtime > 0.0f){ accumtime = 0.0f;} and in updateBullet ?
@olafprinz555
@olafprinz555 3 года назад
@ Maybe u can post this part of code? I got the problem that it looks like i fire 2 Bullets in a row and i mean it have something to do with the accumulated time and firerate.... would be very nice men ^^ ( also happend on pistol with fireRate of 1 -> always shot 2 bullets.)
@MajorParts
@MajorParts 3 года назад
@@TheKiwiCoder I don't get this solution. Could you be a bit more specific please?
@Tinchy2024
@Tinchy2024 Год назад
what the name of background music? that is very well
@deathbykudzu5088
@deathbykudzu5088 3 года назад
I'm having an issue with my raycast Debug.DrawLine at around 9:55. The line is not appearing. I have added Debug.Log(hitInfo.point) to print the endpoint to the console, which works properly, so the ray is being cast and intersecting with objects. Idk why the DrawLine is not working. Anyone have any suggestions? Edit: Never mind I just didn't have gizmos enabled.
@coreygrace8937
@coreygrace8937 3 года назад
i did the same thing lolol
@jeffblankenship4167
@jeffblankenship4167 3 года назад
I ran into the same issue - make sure that both your Scene and Game windows have "Gizmos" turned on :)
@sarkariadmi4058
@sarkariadmi4058 3 года назад
After build muzzle flash is not working please tell me a solution
@AbductionDevlog
@AbductionDevlog Год назад
I have gotten to the end and now the trail and the impact effects have stopped working and the muzzle is constantly firing. isFiring is not constantly on and updates correctly to mouse inputs but the muzzle flash is constantly on. It is spawning in BulletTracer(clone)'s in the Hierarchy but I cannot see them and everything is set up correctly in the inspector. It was all working fine prior to the bulletdrop/speed updates. The bullet trail works fine if I drag the prefab into the scene the same for the hit effects which makes me think it is an issue with the ray cast. I have troubleshot this issue for some time now and can't figure out where I have went wrong as the code looks verbatim to what you have. using System.Collections; using System.Collections.Generic; using UnityEngine; public class RaycastWeapon : MonoBehaviour { class Bullet { public float time; public Vector3 initialPosition; public Vector3 initialVelocity; public TrailRenderer tracer; } public bool isFiring = false; public int fireRate = 25; public float bulletSpeed = 1000.0f; public float bulletDrop = 0.0f; public ParticleSystem[] muzzleFlash; public ParticleSystem hitEffect; public TrailRenderer tracerEffect; public Transform raycastOrigin; public Transform raycastDestination; Ray ray; RaycastHit hitInfo; float accumulatedTime; List bullets = new List(); float maxLifetime = 3.0f; Vector3 GetPosition(Bullet bullet) { Vector3 gravity = Vector3.down * bulletDrop; return (bullet.initialPosition) + (bullet.initialVelocity * bullet.time) + (0.5f * gravity * bullet.time * bullet.time); } Bullet CreateBullet(Vector3 position, Vector3 velocity) { Bullet bullet = new Bullet(); bullet.initialPosition = position; bullet.initialVelocity = velocity; bullet.time = 0.0f; bullet.tracer = Instantiate(tracerEffect, position, Quaternion.identity); bullet.tracer.AddPosition(position); return bullet; } public void StartFiring() { isFiring = true; accumulatedTime = 0.0f; FireBullet(); } public void UpdateFiring(float deltaTime) { accumulatedTime += deltaTime; float fireInterval = 1.0f / fireRate; while(accumulatedTime >= 0.0f) { FireBullet(); accumulatedTime -= fireInterval; } } public void UpdateBullets(float deltaTime) { SimulateBullets(deltaTime); DestroyBullets(); } void SimulateBullets(float deltaTime) { bullets.ForEach(bullet => { Vector3 p0 = GetPosition(bullet); bullet.time += deltaTime; Vector3 p1 = GetPosition(bullet); RaycastSegment(p0, p1, bullet); }); } void DestroyBullets() { bullets.RemoveAll(bullet => bullet.time >= maxLifetime); } void RaycastSegment(Vector3 start, Vector3 end, Bullet bullet) { Vector3 direction = end - start; float distance = direction.magnitude; ray.origin = start; ray.direction = direction; if (Physics.Raycast(ray, out hitInfo, distance)) { hitEffect.transform.position = hitInfo.point; hitEffect.transform.forward = hitInfo.normal; hitEffect.Emit(1); bullet.tracer.transform.position = hitInfo.point; bullet.time = maxLifetime; } else { bullet.tracer.transform.position = end; } } private void FireBullet() { foreach(var particle in muzzleFlash) { particle.Emit(1); } Vector3 velocity = (raycastDestination.position - raycastOrigin.position).normalized * bulletSpeed; var bullet = CreateBullet(raycastOrigin.position, velocity); bullets.Add(bullet); } public void StopFiring() { isFiring = false; } }
@tiagomartins5487
@tiagomartins5487 3 года назад
I installed the "universal render pipeline", to be able to use it in the shader, but the material was transparent, is there any alternative?
@TheKiwiCoder
@TheKiwiCoder 3 года назад
Did you upgrade project materials?
@tiagomartins5487
@tiagomartins5487 3 года назад
@@TheKiwiCoder Yes, I did it, and besides the transparency, some became pink! hahaha but no problem, I used something else
@arslankhan2191
@arslankhan2191 15 дней назад
I saw these videos back in the day now i was working on a Shooting game ran into the same issue about crosshair. I was thinking about the solution. Then i remembered there was a Legend "TheKiwiCoder" who posted the solution about same issue
@ThePixelitomedia
@ThePixelitomedia 3 года назад
Could you please show how you light the scene? I have the same asset but it looks like shit on my pc
@TheKiwiCoder
@TheKiwiCoder 3 года назад
Try adding some post effects with colour grading and ambient occlusion. And bloom for the highlights.
@adinafshar4117
@adinafshar4117 10 месяцев назад
hi agin i find why bullet tracer dose not destroy because i froget enable autodestruct tick in trail renderer component 😅
@adinafshar4117
@adinafshar4117 10 месяцев назад
hi thanks for this tutorial but i have a problem my bullet dose not destroy after maxLifeTime can you help me ? 🙂
@gohelboy
@gohelboy 4 года назад
maybe there is a problem if crosshair goes to sky and bullet shoot them bullet goes to player position how can we fix this ?
@chrisp6882
@chrisp6882 3 года назад
having the same issue
@Nordrag3
@Nordrag3 3 года назад
Maybe use layers to ignore the player / whatever is in the way, also i was using projectile prefabs instead of raycast, that way you need to normalize the direction vector, otherwise it gets faster the further the crosshair target is from the gun
@DocDrowsy
@DocDrowsy 2 года назад
Heya, the gun always seems to fire twice when I click. Any idea why that might be happening?
@DocDrowsy
@DocDrowsy 2 года назад
Never mind, fixed it! The FireBullet() call in StartFiring was happening at the exact same time as when UpdateFiring would call it as well. Just removed the reference in StartFiring and now I'm shooting one bullet when I first click. It's been a few weeks since I last watched this video so maybe I missed a bit where you addressed this.
@sanusingh8328
@sanusingh8328 2 года назад
Even after adding the CrosshairTarget to RayCastDestination, the debugging line is not emitted towards crosshair. Debugging line moving anywhere. PlZzzz Help😭
@Someone-ln8vk
@Someone-ln8vk 2 года назад
Great
@mr_crapto
@mr_crapto 3 года назад
When the bullet's effect is fired when it starts moving in the same direction as the player, the impact of the bullet is supposed not to move, but remains in the same place as the shot... Does anyone know the solution, please?
@goshlok4973
@goshlok4973 3 года назад
Is it parenting your gun object or player object? If yes, the simulation space of that particle system should be set to world space.
@burakgok2909
@burakgok2909 3 года назад
Hello, I have still this bug really what's wrong with cinemachine couldn't understand the bullet goes backwards especially when my character moves right side. if I fire a bullet without moving the character everything is normal. Could you please help me if you know how to solve this bug?
@TheKiwiCoder
@TheKiwiCoder 3 года назад
Is it intersecting with the player? Might need to disable the player layer when performing the ray casts
@frontendhacker
@frontendhacker Год назад
Hi @TheKiwiCoder ! While going through this tutorial, i'm facing an issue that the bullets are not being deleted automatically. Can you help me out?
@angiegaming5107
@angiegaming5107 11 месяцев назад
Same But Trailrenderer is just there Help me Out Please!
@angiegaming5107
@angiegaming5107 11 месяцев назад
i think i found a way just change the bullet to bullets in the bullets.removeall() that fix the error but the trail renderer is still there but it is deleted i think its the matter with garbage collector XD
@nihalpadwal
@nihalpadwal 3 года назад
Hey great vid I did the same but i dont see the red line when i am in game scene i can only see it in Scene scene and also the line dont show up when i look at the enemy head and when i look in the sky Please help
@Jackhowe97
@Jackhowe97 2 года назад
enable gizmos
@chandings
@chandings 3 года назад
Greate tutorial series. Loved it. Has anybody else faced the below issue? hitEffect.transform.position = hitInfo.point; hitEffect.transform.forward = hitInfo.normal; hitEffect.Emit(1); The hitEffect is not facing the surface. As a matter of fact its rotation is unchanged and thus is visible from only one direction and sometimes looks odd. I also tride rotating it to "Quaternion.LookRotation(hitInfo.normal)" n it worsened and was no longer visible in any direction. Could any of you help me here.
@chandings
@chandings 3 года назад
Finally fixed it. I had kept scale 0 and position was not 0. After fixing it started working.
@mr_crapto
@mr_crapto 3 года назад
God...Thank you man
@potat0424
@potat0424 Месяц назад
greeat tutorial, i have only one small problem, the firerate is too fast no matter which value i put in the Fire Rate.
@tegaidogun
@tegaidogun 3 года назад
Can you try like a shotgun systen
@trexarain794
@trexarain794 3 года назад
Please can you show how to add mobile inputs on this game?
@user-rg8pe1qj2t
@user-rg8pe1qj2t 4 месяца назад
IN MY CASE WHEREEVER I CLICKED ON SCREEN LINE IS ONLY DRAWING DOWNWARD SIDE ,,,IS THERE ANY SOLUTION?
Далее
[#06] Weapon pickups: Equipping weapons at runtime
23:24
Unity 3D - Zombie AI Tutorial
1:56
Просмотров 1,6 тыс.
How to make Line of Sight in Unity 2D with Raycast
7:04
I Made a 1D Game 🎮
11:18
Просмотров 1,7 млн
Скажи арбуз😂@I_SpongeBobSquarePants
0:27