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 Firedan1176 · May 30, 2014 at 05:47 PM · raycastbulletgun

Use transform.LookAt with Raycast with a delayed bullet?

So I'm just wanting to create a weapon for my game, and there's 2 ways to do that: Raycasting and with actual physics. But because bullets are too fast for physics, raycast is the other option. I don't want to use straight raycast because that's like a "lazer", and I Want a bullet, so something that's like delayed by a few milliseconds before it "hits" the target. Anyone got any ideas?

Comment
Add comment · Show 1
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 torrente · May 30, 2014 at 06:12 PM 0
Share

Not really an answer, since in truth this sort of thing would be up to personal preference. However, I do not think your idea would feel right. A bullet travels so fast that the actual reaction time from a person would be more than enough to implement what you are looking for. Putting in code to delay the actual bullet by a few milliseconds seems unnecessary. Have you tried to implement the Raycast system yet? I'd try that and see how if feels before putting in the delay.

1 Reply

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

Answer by MikeNewall · May 30, 2014 at 07:07 PM

Using a raycast alone means your projectiles will always follow a linear path, and hits will be instantaneous. If you want to simulate a bullet with a ray cast there are a few things to take into account.

Muzzle velocity is the speed that a projectile leaves the weapon. High caliber rifles have a max muzzle velocity of around 1700 meters per second which means that if we say one unit in Unity is a meter then the distance traveled in a second would be 1700 units. The further you are from the target and slower the bullet the longer it will take to hit the target. If your weapons are used at short to mid range then delaying the ray cast would be barely noticeable, however if you require longer ranged weapons then delaying the raycast is more important. The speed of the bullet will also decrease over its life time with air resistance.

You also need to take into account the accuracy. Weapons don't hit the same point each time they fire like a ray cast does. You can simulate accuracy by adding noise to the position that you cast the ray from.

Because a ray cast by its nature is linear your projectile aren't affected by gravity so they dont have a true trajectory. A projectile moved by physics however would, but it'd be moving too fast to detect a collision. Instead of casting a ray from the weapon you could cast a ray from the tip of the projectile to the position that the bullet will be next frame which can be calculated from the bullets heading and speed. If it hits anything then you know that the next frame the bullet will hit the object.

Not even sure if that answered your question :)

Comment
Add comment · Show 1 · 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 Firedan1176 · May 31, 2014 at 02:33 AM 0
Share

Wow, you did perfectly. Thank you!

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

22 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

Related Questions

How do I create bullet hole for my gun? 0 Answers

Gun Script 1 Answer

Raycast shooting in the middle of the screen 1 Answer

Best way to shoot physical bullets? 2 Answers

gun problems 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