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 sdgd · Mar 15, 2013 at 06:35 AM · c#raycastraydebug.drawline

ray transform.position goes wrong

ok why does first code not working properly?

 Debug.DrawRay (transform.position, new Vector3(transform.position.x + 10, transform.position.y, transform.position.z + 0), Color.red);
 Debug.DrawRay (transform.position, new Vector3(transform.position.x + -10, transform.position.y, transform.position.z + 0), Color.red);
 Debug.DrawRay (transform.position, new Vector3(transform.position.x + 0, transform.position.y, transform.position.z + 10), Color.red);
 Debug.DrawRay (transform.position, new Vector3(transform.position.x + 0, transform.position.y, transform.position.z + -10), Color.red);

this code gives 4 lines in 4 directions correctly

 Debug.DrawRay (transform.position, transform.forward*10, Color.red);
 Debug.DrawRay (transform.position, transform.forward*-10, Color.red);
 Debug.DrawRay (transform.position, transform.right*10, Color.red);
 Debug.DrawRay (transform.position, transform.right*-10, Color.red);


why does first code go in 4 direction forward like:

 \|/

I don't get it...

Comment
Add comment · Show 3
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 Fattie · Mar 15, 2013 at 07:12 AM 1
Share

sdgd, sometimes it's easier to use Debug.DrawLine .. you just give it from/to positions

avatar image sdgd · Mar 15, 2013 at 07:22 AM 0
Share

oh didn't know there are 2 debugs, ...

I just google for debug ray and I got it so I went on that

avatar image Fattie · Mar 15, 2013 at 07:43 AM 1
Share

http://docs.unity3d.com/Documentation/ScriptReference/Debug.html

1 Reply

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

Answer by robertbu · Mar 15, 2013 at 06:50 AM

The second parameter is a direction. It is assumed that (0,0,0) is the basis of the vector, so your rays are the direction those positions are from the origin. Try this instead:

 Debug.DrawRay (transform.position, new Vector3(10, 0,  0), Color.red);
 Debug.DrawRay (transform.position, new Vector3(-10,0,  0), Color.red);
 Debug.DrawRay (transform.position, new Vector3(0,  0,  10), Color.red);
 Debug.DrawRay (transform.position, new Vector3(0,  0, -10), Color.red);

For example now you have a vector that is +10 on the x axis away from the point specificed as the first parameter. Note that the other four DrawRays() are not the same as these (now edited) four. These four will align with the world axes. The other four will align with the rotation of the block.

Comment
Add comment · 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 sdgd · Mar 15, 2013 at 07:24 AM 0
Share

ok thanks

and hey BTW I'm able to accept the answer too ;)

yes I got lazy for 1 answer from all my Q haven't touch unity for about 3 weeks and will have to look in to it

but you don't need to accept it ins$$anonymous$$d of me as I always accept answers with witch I'm most satisfied

avatar image robertbu · Mar 15, 2013 at 03:02 PM 0
Share

I wasn't the one to accept your answer. Anyone with enough $$anonymous$$arma can accept answers. Generally I don't mark accepted for my answers, but might for someone else's answers.

avatar image Bunny83 · Mar 15, 2013 at 03:12 PM 0
Share

Sure ;) Accepting your own answer doesn't give you karma. I barely accept answers since it's the duty of the OP. However i will accept answers which has been posted by the OP on his own question to give him some karma (of course only when the answer makes sense ;)).

Sometimes i accept correct answers to questions that are a year old just to have it closed.

avatar image Fattie · Mar 15, 2013 at 03:20 PM 0
Share

"Sometimes i accept correct answers to questions that are a year old just to have it closed."

Bunn, I'm surprised someone as young as you thinks one year is a year. For me these days two days is a year. I have the same philosophy, I close everything I see that is more than two real days old ;-)

I wonder what the $$anonymous$$arma cut off is to close answers?

avatar image robertbu · Mar 15, 2013 at 03:20 PM 0
Share

I didn't know accepting your own answer doesn't give you $$anonymous$$arma. It make sense.

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

12 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

Related Questions

2 raycasts on the fpwalker/camera 1 Answer

Distribute terrain in zones 3 Answers

Why in Unity3D RaycastHit. textureCoord always return 0,0 after building the project? 1 Answer

[C# / Unity] Raycast Ignoring Self / Offsetting Instantiations? 0 Answers

Raycasting how to find position on end of ray float distance 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