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 oliver-jones · Sep 26, 2013 at 12:51 PM · transformvectorschainmiddle

Find Centre Point of 2 Vectors

Hello,

I want to create a chain type effect, so when I click and drag from my scene, spheres will line them selves up from where I initially clicked, to where I have dragged to.

I've achieved this by using three spheres:

  • One for the starting marker (so where I initially clicked)

  • One for the ending marker (so where my mouse position is currently)

  • And a sphere for the middle point.

The problem is now, is that I want to have multiple middle points. So instead of 1 middle sphere, I want to have 3. And I want them to line up perfectly between the starting marker and the finishing marker:

 if(Input.GetButton("Fire1")){
             isDragging = true;
 
             end.position = hit.point;
             //middle.position = (end.position / 2) + (start.position / 2);
 
             for(var m = 0; m < middles.length; m++){
                 middles[m].position = ((end.position * m / 2) + (start.position * m / 2));
 
             }
         }

Thanks

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
Best Answer

Answer by whydoidoit · Sep 26, 2013 at 12:57 PM

Well just take one position from the other, then multiply that difference by a number between 0 and 1 to get that interval and add on the lower value.

    var difference = start - end;
    var quarterPoint = start + difference * 0.25f;
    var midPoint = start + difference * 0.5f;
Comment
Add comment · Show 11 · 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 oliver-jones · Sep 26, 2013 at 12:59 PM 0
Share

Okay, but what about if I want to make it dynamic? Eg, the further I drag away, the more spheres are initiated - I will then need to calculate them in too

avatar image whydoidoit · Sep 26, 2013 at 01:02 PM 0
Share
    var numberOfSpheres = difference.magnitude / 2;
    for(var i = 0f; i < 1f; i += 1f/numberOfSpheres)
    {
        var spherePos = start + difference * i;
    }
avatar image oliver-jones · Sep 26, 2013 at 01:09 PM 0
Share

So I've done this:

 if(Input.GetButton("Fire1")){
             isDragging = true;
 
             end.position = hit.point;
             var difference = start.position - end.position;
             var numberOfSpheres = difference.magnitude / 2;
 
             for(var i = 0; i < numberOfSpheres; i += 1f/numberOfSpheres){
                    var spherePos = start.position + difference * i;
 
                    middles[i].position = spherePos;
               }
         }

And it crashes every time I run it :/

avatar image whydoidoit · Sep 26, 2013 at 01:12 PM 0
Share

Actually just updated my answer as I screwed up the inc of i

so you want:

  if(Input.GetButton("Fire1")){
      isDragging = true;
 
      end.position = hit.point;
      var difference = start.position - end.position;
      var numberOfSpheres = difference.magnitude / 2;
 
      for(var i = 0; i < numberOfSpheres; i++){
            var spherePos = start.position + difference * ((float)i/numberOfSpheres);
 
            middles[i].position = spherePos;
      }
    }
avatar image whydoidoit · Sep 26, 2013 at 01:17 PM 0
Share

Oh and you need a $$anonymous$$athf.FloorToInt on the number of sphere setting:

   var numberOfSpheres = $$anonymous$$athf.FloorToInt(difference.magnitude/2);
Show more comments

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

16 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

Related Questions

How would you fake air resistance? (c#) 2 Answers

How Vectors work and how I should use them? 1 Answer

Vector movement according to rotation glitching out at non-square angles. 0 Answers

acessing vector coordinates that are stored in a variables 2 Answers

Middle of screen vector 3? 2 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