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 1337GameDev · Nov 20, 2011 at 02:02 AM · positioncomponentvector2deltatime

Vector2.magnitude and Touch.deltaPosition understanding....

I am curious what a vector2 is made up of. I know it has an x and y component, but does it have a direction component as well? I would assume not as it just stores the coordinates of a location.

If the vector2 stores only x,y components, why does it have a magnitude? Does that method actually figure out the hypotenuse formed form the two side lengths x and y in a triangle?

Why is this useful except at origin? Wouldn't you mainly use triangles between separate vector2 objects?


My second question is about Touch("an index").deltaPosition.

When referencing where a touch was previously to find out direction it has moved you use the expression:

(Input.GetTouch(0).position - Input.GetTouch(0).deltaPosition)

to find out where it was last update. Do you ALWAYS subtract? But then that means deltaPosition has to be negative sometimes. When is it negative?

How would i also set up debugging or a simple way to see variables at runtime for an android application to check this? (preferably without using a LAN as my only option is AdHoc and android (even with an AdHoc hack to enable it) won't connect to my pc. How would i make a counter that is displayed on screen to keep track of variables then?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Eric5h5 · Nov 20, 2011 at 03:16 AM

A Vector2 is two floats, and magnitude is simply the square root of x*x + y*y. Presumably it looks something like this (simplified):

 struct Vector2 {
     public float x;
     public float y;
     public float magnitude {
         get {return Mathf.Sqrt (x*x+y*y);}
     }
     
     public Vector2 (float x, float y) {
         this.x = x;
         this.y = y;
     }
 }

x and y are whatever you say they are. They can be coordinates, or a direction, or something else. As for the rest, you should really just ask one question per question.

Comment
Add comment · 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
2

Answer by aldonaletto · Nov 20, 2011 at 04:25 AM

@Eric5h5 is right: you should post 2 more questions.
1- Let me answer the second question: deltaPosition is the touch displacement since the last change, and its polarity and value depend on the direction of movement. You must always subtract deltaPosition from GetTouch[n].position to find the previous position.
2- Answering the 3rd quetion: you can use OnGUI to show some variable of interest:

var speed: float; // <- you are interested in this variable

function OnGUI(){ // show the variable in a GUI.Label: GUI.Label(Rect(10,10,320,50),"Speed:"+speed.ToString()); }

Comment
Add comment · Show 2 · 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 1337GameDev · Nov 20, 2011 at 09:08 PM 0
Share

What do you mean by displacement, is that just a magnitude or does it have a negative value sometimes? What occasions would it? Any examples of values and situations for deltaPosition? The documentation doesnt shiw cases and values at all.

I thought i would save time by combining into one. Guess ill have to post more then.

How would i do that using texture gui? I heard ongui is terrible for mobile devices do to constant gui element calls.

avatar image aldonaletto · Nov 21, 2011 at 03:01 AM 0
Share

This displacement is a Vector2: its x and y components hold the difference between the current and the last positions. If the touch is at [50,50], for instance, and you move the finger to [20,70] - what I suppose is to left/up - deltaPosition will be [-30,20] (result of current point [20,70] $$anonymous$$us old point [50,50]).

About the GUI: I suppose OnGUI is more expensive than GUIText, since it's called several times during each Update. You can use a GUIText for debugging:

var gText: GUIText; // drag the GUIText here from the hierarchy

function Update(){ var debug: String; debug += var1+"\n"; // add the variables you want to debug += var2+"\n"; // watch with a new line at the end debug += var3+"\n"; // to have one variable per line ... gText.text = debug; // show the string created }

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

ECS find entity position component 0 Answers

vector2 is 0 to 1? 2 Answers

rigidbody.velocity is queued for processing after rigidbody.position 0 Answers

Can you set a component (audio source) position manually 2 Answers

Make the character follow the images one by one smoothly 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