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 UncleGubbsy · Apr 08, 2016 at 01:04 PM · raycastvector3for-loop

Right Click and Drag Formation Line RTS

Hello, I have a question aobut my script. In this script you can Right click and drag, upon the release of right click it creates vector3s with an even distribution between all of them. My question is that the first vector3 created looks at the second raycast point. All of the other vector3s are added on the xPos of the first one. However, they are not adding from the first point, instead, they are adding from the world position, not local. Also cubes spawn at the vector3s to debug. So, how do I make the cubes Instantiate on each vector3 a certain amount of units away from the first vector3, locally.

     RaycastHit hit;

     Ray r = Camera.main.ScreenPointToRay(Input.mousePosition);
     
     
     if (Input.GetMouseButtonDown(1) && !firstClicked && Physics.Raycast(r, out hit)) //Right Clicked
     {
         firstRaycast = hit.point + hit.normal;
         
         
         Debug.Log(firstRaycast + " First Raycast");
         Debug.Log(firstClicked);
         firstClicked = true;
     }

     RaycastHit hit2;
     Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
     if (Input.GetMouseButtonUp(1) && firstClicked && Physics.Raycast(ray, out hit2)) //Right Clicked again
     {
             GameObject placeHolderInstance = Instantiate(placeHolder, firstRaycast, Quaternion.identity) as GameObject;
             secondRaycast = hit2.point + hit2.normal;
             placeHolderInstance.transform.LookAt(secondRaycast);
             Debug.Log("Second raycast stored");
             float distance = Vector3.Distance(firstRaycast, secondRaycast);
             Debug.Log(firstRaycast + " First Raycast");
             Debug.Log(distance + " Distance");
             Debug.Log(unitsSelected.Count + " Units Selected");
             float interval = distance / unitsSelected.Count;
             
             for (int i = 1; i<unitsSelected.Count; i++)
             {


             Vector3 newPoint = new Vector3(firstRaycast.x + interval * i, firstRaycast.y, firstRaycast.z);
             placeHolderInstance = Instantiate(placeHolder, newPoint, Quaternion.identity) as GameObject;
             
             Debug.Log(interval + " Interval");
             }
         
         firstClicked = false;
     }
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

0 Replies

· Add your reply
  • Sort: 

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

68 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

Related Questions

how to check if an object is betwen enemy and player 1 Answer

Ballistic vector technique 0 Answers

Clamp vector values to a minimum circular radius around player? 1 Answer

assigning several positions and call array of raycasts 0 Answers

RaycastHit.normal and Vector3.reflect problem 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