- Home /
Bullet Effect
Hey guys! I was wondering how I could do a bullet effect like in Source Engine. I know Source Engine uses a different type of RayCast (I think its RayTracing, I could be entirely wrong). I came up with two methods that might work but have my concerns on both. I would be thankful for some information on how to procede.
Method 1: Bullet Object - A bullet is sent along the raycast to the hit position and destroys itself as soon as it collides with anything. The major problem: Either I have a very fast Bullet which is hardly noticeable (like in Source Engine). This is more realistic (as RayCast hits the object immediately), but it is very hard for Unity to detect collisions of fast moving objects and the bullet might not be destroyed. Or: I have some slower bullets which are more detectable, but if the object that is hit moves, the bullet might go somewhere else and just look unrealistly. Maybe someone knows how to get Unity to detect fast bullets?
Method 2: Draw Line - I also had Draw Line in mind, as it hits the hitpoint in perfect synchronization with the raycast, but also looks unrealistic because there is not movement, its just a line.
Anyway, you have seen my ideas, please feel free to share any of your own or improvements of the ones I have and opinions on which you think would work the best or easiest.
Answer by Dracorat · Nov 12, 2013 at 08:29 PM
Raycast
will detect an intersecting collider between the origin and the target distance (which could be a long distance).
In either case you're asking for, it's what you want.
For an instantaneous bullet, Raycast from the muzzle (or other appropriate location near the pawn for the player in question) in a direction according to the facing of the weapon and a distance sufficient to cover a reasonable shot range. The first collider hit will be reported. If you need to allow for bullet penetration, use RaycastAll
and sort by distance, then handle penetration according to your algorithm for penetration.
As for traveling bullet (like if you want them to leave tracers) then just make the bullet a tracer graphic and still make it extremely fast. Raycast from the last known position of the bullet to the new position (An easy way would be to place an empty at the last location and then using LookAt
to look at the current position - then raycast according to the difference in distance between the positions)
Raycast from the last known position of the bullet to the new position
Linecast is what you want in this case. :)
True - then you wouldn't have to trouble yourself with LookAt and distances. =)
Sorry to reopen this but I have been doing some thinking and you busy seem to know your stuff. How could you make something like this where you can see the feint trace of the bullet?
https://www.youtube.com/watch?v=CcYgTP$$anonymous$$$$anonymous$$8Sw
Yes, this game is made in Unity which is why I am asking if some of you had an idea. Thanks for your replies!
Please ask the question in a new question. The policy is one topic per question - it keeps replies and searches useful.
Its actually the same question but your right: Im gonna ask a new one and reword it a bit so that I get the answer I need. Thank you!
Answer by Yokimato · Nov 03, 2013 at 10:33 PM
I would freeze game time (I.e players and other entities are frozen for bullet cut scene) and then "ride" the bullet with your camera, at a nice slower speed, until it collides. I'd cut the audio so people get the time concept. It is bullet TIME after all :P
I don't think you understand what I want to do. I simply want to make something shoot from the gun, not some fancy bullet time.
Yep, he does not mean bullet time like $$anonymous$$atrix or $$anonymous$$ax Payne, he is asking about Frame-miss principle. High velocity object going through walls. I think I get it this way.
Your answer
Follow this Question
Related Questions
RayCast Problem : 2d 1 Answer
Optimization of bullet hit calculation per frame 1 Answer
Need a script for a gun that shoots bullet using raycast 2 Answers
shoot game - 2 problems 1 Answer
Shoot with ray cast angle 1 Answer