Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
Question by MushyAvocado · Mar 22 at 04:31 AM · gunfire

Prevent bullets from trailing behind crosshair at high range?

I'm making a first-person shooter. I have a gun that casts a ray to check where the bullet will hit and calculates accordingly to make sure the bullet actually hits the crosshair (not straight out from the gun, which would hit below and to the right of the crosshair). I have a bullet gameobject that is spawned, which simply goes from the gun to the pre-calculated crosshair hit point. The bullet does nothing but travel there at a high speed (100 units per second.) However, when shooting at high range the bullets appear to trail behind the crosshair when looking around and shooting, which is not the effect I want to achieve. Suggestions on how to fix this?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Acdia · Mar 23 at 08:44 AM

Hey! I think the question is, what effect you want then, since a physical bullet normally will travel in a straight line after being shot (even in real live). I think there are several options to get the bullet hit accurately.

  1. Speed - 100 Units per second is, compared to a real live bullet, rather slow (~800 m/s). So you could just speed up the bullet even more. The downside is, that collision detection gets a real pain at this speed - which probably doesn't matter, if you use a raycast to check the collision before even shooting the projectile. But then again, if you want to hit accurately and don't care about gravity, you could get rid of the bullet:

  2. No bullet - Instead of using an actual projectile, you can just use some effect to give the illusion of a bullet flying (at 800 m/s you probably wouldn't see anything, but some visuals are often wanted). You could, for instance, use a line renderer. Just set the start and end point to the pistol tip and the hit point and put some animation on it, that it quickly flashes. Make sure to update the start position to the pistol, while the animation is playing. This way the line will be correctly rendered and isn't flying away.

  3. home-seeking-missile-ish-crap - You can give a pointer to the playerObject to the bullet and let it read the current hit location (perform raycast every Update). Then subtract the bullet position from the hitPoint position, normalize the vector, multiply it with the desired speed and set it as the velocity of the bullet. This way the bullet should always fly towards the crosshair. Despite making no sense, since the bullet now can fly in an arc, whis probably isn't what you want, it could look pretty fun - maybe a new idea for a game mechanic?

Anyway, I would go with the second approach - I hope this contains something useful.

Comment
Add comment · 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

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.

Follow this Question

Answers Answers and Comments

133 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 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 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 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 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 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 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 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

Rapid fire to Instantiated prefab 2 Answers

Reload system staying at full magazine for as long as reload time? 1 Answer

How to add a gunshot sound to this script? 1 Answer

How do you add force to a clone after you spawn it? 3 Answers

How to create spawnPoint for bullet shoot 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