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 NuclearBUSE · Jun 11, 2013 at 06:56 AM · rayray cast

Ray search

Hello first time here. Here's my problem : alt text

I'm working on 2D (X,Z) Y is constant at 60

I want to make sure that an intersection can "search" around for a Road (these are simple cubes)

These cubes have scripts attached to em (Road,Intersection)

So, in my script, I have this :

 #Intersection#
 //posXZ is a table that contains the coords of the intersection (X,Z)
 vectu = new Vector3(posXZ[0]-2,60,posXZ[1]);
 ray = new Ray(vectu,vectu - new Vector3(0,60,0));
 RaycastHit hit ;
 if (Physics.Raycast(ray,out hit))
 {
 //DO SOMETHING
 }

My problem is that, i don't know how to use properly the direction mentionned in the manual for RAY. I know that i have to create a total of 4 rays which are gonna check in a range of 2 units if there's a cube with the tag "road" but i don't really know how to use the direction.

Can somebody explain with a little diagram please ?

example.png (54.3 kB)
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
1

Answer by lighting · Jun 11, 2013 at 07:22 AM

I think, that Scripting Reference with description of Ray() constructor is very helpful. There is example: public Ray ray = new Ray(transform.position, transform.forward);

In your case the solution could be (depending on how you have the coordinates setup):

  • rayUp = new Ray(transform.position, Vector3.up);

  • rayDown = new Ray(transform.position, Vector3.down);

  • rayLeft = new Ray(transform.position, Vector3.left);

  • rayRight = new Ray(transform.position, Vector3.right);

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 NuclearBUSE · Jun 11, 2013 at 09:23 AM -1
Share

Oh god....I'm so dumb! Didn't saw these Vectors -_-' Thanks ! The Vectors left,right,forward,back are using (0, 0, 1) as coords, will it take the first object that it encounters? Or the last ? (for example, if there's something behind the road) ?

avatar image
1

Answer by NuclearBUSE · Jun 11, 2013 at 09:27 AM

Yeah, haven't seen these functions... :( It's working anyway, thanks !

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

15 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

Related Questions

is it possible to have raycasts to cover the whole screen in one Update() time? 0 Answers

SORPG: Distance problem? 1 Answer

Confused as to how my RaycastHit script works 1 Answer

Shooting with touch 1 Answer

Ray direction, projection matrix 0 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