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 lemiwinks · Aug 06, 2013 at 10:21 PM · dragplane

can I drag out the scale of a plane?

hey all,

Im trying to have an effect where the player will click on the screen, and while holding the mouse down, they are able to drag out an arrow shape which points at the position where the mouse click was 1st made.

i know id need the positions of the mouse click and the currrent position, but im not sure how to instantiate a plane which pointed towards the startPOS while the rear end is linked to currentPOS, thats if its even possible?

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 robertbu · Aug 07, 2013 at 12:47 AM

The Vectrosity package in the Asset store makes drawing lines and arrows easy. Depending on what you are doing, it may be a good solution.

Here is another solution. To test it:

  • Get the CreatePlane script from the Wiki.

  • Create a 1 unit Vertical plane

  • Put whatever material you want on the plane. Note the point of the arrow should be up. You will have to do the arrowhead as a separate object if you don't want it stretched.

  • Attach this script

  • Set the x in the scale to .001.

Hit play and click and drag.

 #pragma strict
 
 private var pos1 : Vector3;
 private     var pos2 : Vector3;
 var objectHeight = 1.0;  
  
 function Update () {
  
     if (Input.GetMouseButtonDown(0)) {
        pos1 = Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.nearClipPlane + 0.5);
         pos1 = Camera.main.ScreenToWorldPoint(pos1); 
         pos2 = pos1;
  
     }
  
     if (Input.GetMouseButton(0)) {
        pos2 = Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.nearClipPlane + 0.5);
         pos2 = Camera.main.ScreenToWorldPoint(pos2); 
  
     }
  
     if (pos2 != pos1) {
        var v3 = pos2 - pos1;
         transform.position = pos1 + (v3) / 2.0;
         transform.localScale.y = v3.magnitude;
         transform.rotation = Quaternion.FromToRotation(Vector3.up, v3);
     }
 }


Comment
Add comment · Show 8 · 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 lemiwinks · Aug 07, 2013 at 10:04 AM 0
Share

thankyou, howevere that didnt seem to work, the x scale stayed on .001 and ony the y axis was changing as a dragged :S

avatar image lemiwinks · Aug 07, 2013 at 10:05 AM 0
Share

i should also mention its an orphographic view

avatar image robertbu · Aug 07, 2013 at 11:42 AM 1
Share

$$anonymous$$eep this x axis the same was the intent. The code was for drawing lines, so you use a line texture and can draw out an "arrow". But if you want to scale both x and y, just insert the following line between line 25 and 26 above:

     transform.localScale.x = v3.magnitude;
avatar image lemiwinks · Aug 07, 2013 at 02:03 PM 0
Share

that actually is pretty much bang on! thankyou.. the only problem i have left with it is its tilted when i drag it out, what the best way fro me to fix it so its locked flat parallel to the floor

avatar image robertbu · Aug 07, 2013 at 03:14 PM 0
Share

I changed a couple of lines. $$anonymous$$aybe this is what you are looking for:

 private var pos1 : Vector3;
 private var pos2 : Vector3;
 var objectHeight = 1.0;  
  
 function Update () {
     if (Input.Get$$anonymous$$ouseButtonDown(0)) {
        pos1 = Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.nearClipPlane + 0.5);
         pos1 = Camera.main.ScreenToWorldPoint(pos1); 
         pos2 = pos1;
     }
  
     if (Input.Get$$anonymous$$ouseButton(0)) {
        pos2 = Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.nearClipPlane + 0.5);
         pos2 = Camera.main.ScreenToWorldPoint(pos2); 
     }
  
     if (pos2 != pos1) {
        var v3 = pos2 - pos1;
         transform.position = pos1 + (v3) / 2.0;
         transform.localScale.y = $$anonymous$$athf.Abs(v3.y);
         transform.localScale.x = $$anonymous$$athf.Abs(v3.x);
     }
 }
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

14 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

Related Questions

Multiple Cars not working 1 Answer

Click and drag a plane 1 Answer

Unity2D - Box Collider 2D problem 0 Answers

Need a little help in script 1 Answer

Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 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