• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by Borzi · Nov 03, 2013 at 02:04 PM · collisionraycastbulletshoot

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.

Comment
Mikael-H

People who like this

1 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image

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)

Comment
Josh707
Mikael-H

People who like this

2 Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image fafase · Nov 12, 2013 at 08:49 PM 1
Share
   Raycast from the last known position of the bullet to the new position

Linecast is what you want in this case. :)

avatar image Dracorat · Nov 12, 2013 at 09:07 PM 0
Share

True - then you wouldn't have to trouble yourself with LookAt and distances. =)

avatar image Borzi · Nov 26, 2013 at 03:47 PM 0
Share

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=CcYgTPMK8Sw

Yes, this game is made in Unity which is why I am asking if some of you had an idea. Thanks for your replies!

avatar image Dracorat · Nov 26, 2013 at 04:33 PM 0
Share

Please ask the question in a new question. The policy is one topic per question - it keeps replies and searches useful.

avatar image Borzi · Nov 27, 2013 at 07:16 PM 0
Share

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!

avatar image

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

Comment

People who like this

0 Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Borzi · Nov 12, 2013 at 08:01 PM 0
Share

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.

avatar image fafase · Nov 12, 2013 at 08:50 PM 0
Share

Yep, he does not mean bullet time like Matrix or Max Payne, he is asking about Frame-miss principle. High velocity object going through walls. I think I get it this way.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

RayCast Problem : 2d 1 Answer

Bullet Shoot with RayCast don't destroy onCollisionEnter 1 Answer

Destroy Projectile on collision 3 Answers

Why won't my bullets detect a collision and be destroyed?... 4 Answers

Raycast bullet collision problem 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges