Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by CassMeck · Apr 11, 2017 at 03:57 PM · raycastpositionobjectsselectiongridaround

To send Raycasting to four corners ?

Measure the distance between the mouse click and the box.I am trying to do it using code Vector3.Distance.

alt text

Hi, I click on the object on the grid with the mouse and I want you to show the boxes that can be clicked with the next mouse.I want to do, just be able to choose the boxes around. So white boxes will not be selected.I have read similar topics.But, I could not find the answers I wanted.

  • hit.transform.position.x +1

  • hit.transform.position.x -1

  • hit.transform.position.y +1

  • hit.transform.position.y -1

if (Physics.Raycast (ray, out hit)) {} using, when I click the box, show me around green boxs.I have read similar issues but haven't found the answers I wanted. If the label of the boxes around is "whitebox", (hit.collider.gameObject.tag == "whitebox") These boxes are turning into green color. If the label is a red box, these boxes have already been selected.

EDİT 1 - Update:

I wrote a code like the following, but it did not work.

         redbox = GameObject.FindGameObjectWithTag("redbox").transform;
         
         Vector3 mousepos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
         distance = Vector3.Distance (redbox.position, mousepos);

         if(Input.GetMouseButtonDown(0)) 
         {
         if(distance < 1.0f){print("Near the box");}
         if(distance > 1.0f){print("Away from the box");}
         }

EDİT 2 - Update:

When I looked at the box library, I compared it with the SphereCast code. It did not work the way I wanted when I wrote it like this.

 Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
 RaycastHit sphereHit;
 if (Input.GetMouseButtonDown (0)) 
 {
 if (Physics.SphereCast (ray, 1, out sphereHit)) 
 {
 if (sphereHit.collider.gameObject.tag == "redbox") { print ("Near the box"); }
 if (sphereHit.collider.gameObject.tag == "whitebox") { print ("Away from the box"); }
 }
 }

EDİT 3 - Update:

  • I'm still investigating.I'm trying new methods because the answer is notcoming.Now I am looking at whether there is an object with a "redbox" tag around it by sending a raycasting.

  • The raycasting is going straight.Okay, but I want you to send a raycasting to the four corners when you get hit.

  • The angle at which the red raycasting comes is not fixed.Whatever the angle, the green raycastings must go in the same direction.

alt text

 if (Physics.Raycast(mouseRay.origin, mouseRay.direction, out hit))
 {
 if (hit.collider.transform.tag == "redbox") 
 {
 Debug.DrawRay (mouseRay.origin, mouseRay.direction * 50, Color.red);
 }

selected.png (19.1 kB)
drawray.png (107.1 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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Cuttlas-U · Apr 12, 2017 at 06:40 PM

hi; i did similar thing in my game its not like your way but i described it here so maybe usefull;

this show's me where i can go with red triangles;

Image 1

what i did was creating 3 GameObjects with smaller triangle form collider on them like this :

Image 2

then i create a script and attach to those colliders to pass their objects to their parent with the first trigger , the parent got all those objects and based on their name put them in an special array , when the parent full the array and he already know all of the triangls around him i created a function to destroy the colliders around him cause they are not any more needed;

so this is a tricky way and optimized to do it;


images.png (98.2 kB)
images.png (98.2 kB)
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 CassMeck · Apr 12, 2017 at 07:35 PM 0
Share

Firstly, thank you for your reply. :) Yes, I'm trying to do something like that.I was trying to do what you told me in my first experiments.But since the number of grids is not certain, I thought the distance measurement would be more accurate.I'm one step closer to the code I write every time.But he does not work like I want to. :) Physics.SphereCast method is good but I am making mistakes somewhere.

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

127 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 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 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 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 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 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

Check if position is inside a collider 5 Answers

Raycast on left side and right side of the player 1 Answer

Raycast Start Position 0 Answers

How can I find object ? 2 Answers

what's wrong with my waypoint placer script 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