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 ExpiredIndexCard · May 28, 2013 at 08:00 PM · physicsraycastbullet

How to scatter Ray Casts? Video Example Included.

How can I scatter raycasts and not have it directly forward of the player? I also would like it to not be instantly shot. It should take time to get to the target. Look at this video and you will understand what I want. It starts at 1:37. Here: http://www.youtube.com/watch?v=nVvqJ1KKM04

Thanks guys!

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 ExpiredIndexCard · May 28, 2013 at 09:53 PM 0
Share

bump......

2 Replies

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

Answer by llSalvationll · May 28, 2013 at 10:15 PM

You asked 2 questions: 1-Scattering Bullets- For this piece, it sounds like you probably already have a vector pointing directly forward of the player. From this vector you can use the Random class to add/subtract(or multiply) components(x,y,z) of the vector to alter the course 'randomly'. You will need to experiment until you find value ranges that get you the scatter behavior you want.

2-Delay in reaching target- If you want a delay in reaching the target, you probably don't want to use a raycast at all, but rather instantiate a projectile - i.e. create a gameObject of some kind. Give the object you instantiate the normalized vector you calculated in the scatter logic, and have it translate toward that point at whatever 'speed' you like and multiply that by delta time. Psuedo-code looks something like this: bulletTransform.Translate(normalVector bulletSpeed Time.deltaTime). You'll likely have to experiment with the speed value here as well until you get something you're happy with. Hope this helps you.

Comment
Add comment · 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 ExpiredIndexCard · May 29, 2013 at 06:20 AM 0
Share

But I'm the video the ray cast took time to get to the target I don't want to instantiate bullets I want to use ray casts. Thanks for the nice reply

avatar image llSalvationll · May 29, 2013 at 02:03 PM 0
Share

The video shows rendered lines. The built-in raycast for Unity does not have a visual component or speed to it. You can use the logic above to get your random vectors and then multiply those vectors over several frames to increase their length. It looks like in the video they're using debug.drawline to show the size/location of the raycasts they're doing - you'll notice the line just gets longer and longer until it hits something (or goes off the screen).

avatar image
0

Answer by hd27 · May 28, 2013 at 10:19 PM

You can try taking the forward vector (the direction your shooting) and then cast the rays in a random range around that vector.

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

14 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

Related Questions

Best way to shoot physical bullets? 2 Answers

Particular collider not working properly... 1 Answer

Multiple raycasts in same fixedupdate 3 Answers

Physics.SphereCastAll with triggers 1 Answer

Raycasting to the bottom side of a plane? 2 Answers


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