• 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
Question by Firedan1176 · May 29, 2014 at 12:44 AM · c#androidgamelookatsimple

Connecting an object to 2 others

I'm trying to develop an android game. There are 2 spheres in the game the user can drag around. I have a plane in the middle. I have set the plane to constantly adapt the length to the distance between the two spheres. I want the line to basically be attatched to the two spheres at either end, and when you move one, it will look like you're just stretching it out (but not thinning). The problem is, transform.LookAt doesn't work because it pivots around the middle, not the sphere the user isn't dragging. Anyone got a way to do this?

Comment

People who like this

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

Answer by MikeNewall · May 29, 2014 at 04:33 AM

In the scene view create a quad and rotate it 90 degrees in the X axis. Set the X scale to however wide you want the plane to be.

You need to make sure the pivot of the plane is at its edge, so translate it -0.5 in the Z axis, then create an empty game object (at the world origin) and parent the quad to it.

The script to control the direction of the plane is really simple

 public Transform pointA, pointB;
 public GameObject plane;

 void Update(){
     plane.transform.position = pointA.position;
     plane.transform.LookAt(pointB.position);
     plane.transform.localScale = new Vector3(1, 1, Vector3.Distance(pointA.position, pointB.position));
 }

You set the position of the plane to always be at the same position as pointA. We moved the pivot so this will align one edge with pointA. Then you use transform.LookAt to look at pointB, which will rotate around the pivot constrained to pointA.

Because the quad has a scale of 1 in Z 1 unit in scale equates to one world unit so you can use the distance between the points to work out the new scale.

Hope that helped.

Mike

Comment

People who like this

0 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 Firedan1176 · May 30, 2014 at 04:22 PM 0
Share

Thanks, but I figured it out. I forgot to add the transforms of the two and divide it (then set the middle object to that). Thanks though

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

21 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

Related Questions

Unity: C#: Eyes look at mouse: HELP!! 3 Answers

Multiple Cars not working 1 Answer

How Cast a ray between two points and return all points intercepted? 0 Answers

how do i Disable and Enable buttons? 2 Answers

Hey guys, could anyone please help me with a platform game I am working on. The player goes left and right like doodle jump. It does work just not very smoothly. Thanks :) 1 Answer


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