• 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 sam32x · Sep 08, 2011 at 09:14 AM · raycastbulletsomething

how to make it so i can see a raycast

ok heres my raycast script

 var damage : float = 1;
 function Update(){
    if(Input.GetButtonDown("Fire1")){
       FireOneShot();
     }
 }
 
 function FireOneShot(){
    var direction = transform.TransformDirection(Vector3.forward);
    var hit : RaycastHit;
 
    if (Physics.Raycast (transform.position, direction, hit, 300)) {
    Debug.DrawLine (transform.position, hit.point, Color.cyan);
 
    hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
 }
 }

how do i make it so i can see the raycast bullet? i figured that

 Debug.DrawLine (transform.position, hit.point, Color.cyan);

would draw a blue line, but it didnt.

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

2 Replies

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

Answer by CHPedersen · Sep 08, 2011 at 09:33 AM

Debug.DrawLine works just fine, but you have to give it the proper arguments. If you call it outside of Update, and all you supply is a startpoint, an endpoint and a color, the function draws a line for just 1 frame, like the docs say:

http://unity3d.com/support/documentation/ScriptReference/Debug.DrawLine.html

If your game renders more frames/sec than 60, then chances are the frame that contained the ray got overwritten in the framebuffer before your monitor asked for an update, and consequentially, you'll never see it even for a splitsecond.

Add some number of seconds after the color so the ray stays visible for a time to see it, and remember that the lines drawn by Debug.DrawLine are Gizmos! (IMPORTANT, this had me scratching my head for an unreasonably long time before). This means you have to turn on Gizmos (top right corner, next to the Stats button) to see it, or the ray stays invisible.

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 isteffy · Apr 17, 2016 at 10:30 AM 0
Share

The problem with DrawLine and DrawRay is that neither can handle a layermask param. How can I draw a line so that it ignores or only hits certain objects?

avatar image
0

Answer by icecold043 · May 02, 2020 at 07:59 AM

I don't understand why they just don't let us make raycasts appear like gizmos in the scene view, if you make a mistake in your drawray, you'll think your raycast is not good so you'll change it, then you'll think it's good but it's not because you changed the value. One mistake and it's broken :/

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

What is this variable type? 2 Answers

Use transform.LookAt with Raycast with a delayed bullet? 1 Answer

Should I use raycasting or colliders? 1 Answer

Bullet Spread with Raycast/RigidBody Triangulation? 1 Answer

Ray curve for bullet gravity effect, or any way to make it 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