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 /
This question was closed Apr 06, 2016 at 11:18 AM by UncleGubbsy for the following reason:

Question is off-topic or not relevant

avatar image
1
Question by UncleGubbsy · Apr 04, 2016 at 07:47 PM · vector3listforeachindexof

Total war Style Movement System with Right Click

/*

     pseudo code for Total war syle -Right Click and Drag Move- 

     Right Click and Drag to place the units where you want them in a straight line, each offseted from one another by how far you drag the line.

     public List<GameObject> unitsSelected = new List<GameObject>(); *already made*

     int offset

     This is used for the left click select marquee. There is more to it but, all I need is to duplicate it and use the selection.x variable.
     I changed the left click to a right click
     -----------------------------------------------
     if (Input.GetMouseButtonDown(1))
     {
         startClick = Input.mousePosition;
     }
     else if (Input.GetMouseButtonUp(1))
     {
         startClick = -Vector3.one;
     }
     if (Input.GetMouseButton(1))
     {
         selection = new Rect(startClick.x, InvertMouseY(startClick.y), Input.mousePosition.x - startClick.x, InvertMouseY(Input.mousePosition.y) - InvertMouseY(startClick.y));
         if (selection.width < 0)
         {
             selection.x += selection.width;
             selection.width = -selection.width;
         }
         if (selection.height < 0)
         {
             selection.y += selection.height;
             selection.height = -selection.height;
         }
     }
     -----------------------------------------------
     This is what I have a question about.

     if(Input.GetMouseButton(1)){

         Simple Raycast here.

         offset = selection.x / 2;  The selection.x above ^^^^ Also divide by 2 to make it a bit smaller and more useful.
         
         foreach(GameObject unit in unitsSelected){

             Create a new Vector 3 or empy gameobject (essentially a transform) and assign each unit in unitsSelected their own new transform.

             So each unit will have a place to go after you release *right click*.

             Vector 3 unitTransform = hit.point + offset * unit.IndexOf(unitsSelected); Maybe this will work? If I were to only add the offset from where you click all the units would be in the same place, so,
             multiplay by the place those units are in, in the list to find where hey should be in the line starting from 0.
             
             So the first should be on hit.point. because multiplying by 0
             Second should be an offset away because multiplying by 1
             So on.....

             When that's all done, then we can talk about rotation.

             We need to find the center point of all the units that are selected. 

             There was another post about this.

             http://forum.unity3d.com/threads/rts-unit-formation.169319/

             Velo222 gives a rough idea on how to go about it.

             Essentially rotate the new Rectangle we made/new line, around the center point of only the Units that are selected. I have no clue on how to do this. This isn't priority anyways.

             When that's all done if(Input.GetMouseButtonUp(1)) Move unit.transform.position to unitTransform/new Vector3 we made?

         }
     }

My main question is just how to go about this. Am I on the right track or should I steer a certain way somewhere else. I'm not looking for actual working code, I just want some ideas you might have on how to solve this problem. If anyone has any tutorials about this please share them, I haven't found any specifically about this.

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

  • Sort: 

Follow this Question

Answers Answers and Comments

57 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

Related Questions

Comparing distance of vector 3's on a dynamic growing list 0 Answers

"InvalidOperationException Collection was modified" in a foreach loop 0 Answers

can't save values from another class to a list 1 Answer

Unique list of Vector3's 1 Answer

c# foreach does not work 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