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 Essential · Jan 28, 2012 at 06:52 AM · vector3vector2comparison

greater or less than with vector coordinates

How do I compare two Vectors and ask, "if either of the vector points is greater than equivalent points on this other vector" or "if either one of the vector points is greater than this number"?

I could do the check one at a time using x and y but I'm wondering if there's a simpler solution.

 // Get the target position in viewport space. The bottom left is (0,0) and the upper right is (1,1)
     private var targetViewportPosition : Vector2;
     targetViewportPosition = camera.WorldToViewportPoint (target.position);
 
 // Set bounding box limits
     private var boundingBottomLeft = Vector2(0.2, 0.2);
     private var boundingTopRight = Vector2(0.8, 0.8);
 
 if (boundingCheck
     && (targetViewportPosition < boundingBottomLeft
         || targetViewportPosition > boundingTopRight))
Comment
Add comment · Show 4
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 syclamoth · Jan 28, 2012 at 07:00 AM 0
Share

Yeah, I'm pretty sure that one way or another you'll end up having to compare them one at a time. On the other hand, there's no reason why you can't write a function that does that automatically, and just use that as a shortcut (ins$$anonymous$$d of having to write it out every time). It's the wonderful thing about turing-complete languages- if a function that you need doesn't exist, you can just write one!

avatar image Essential · Jan 28, 2012 at 07:05 AM 0
Share
 if (boundingCheck && (targetViewportPosition.x < boundingBottomLeft
                         || targetViewportPosition.y < boundingBottomLeft
                         || targetViewportPosition.x > boundingTopRight
                         || targetViewportPosition.y > boundingTopRight))

That's the best I can do I suppose. I only need to check once but if I do need to check multiple times I'll create a function to do it. Thanks! :)

avatar image AlucardJay · Jan 28, 2012 at 07:10 AM 0
Share

i'm really a noob, but this is what i had while running some tests : // GUI

function OnGUI ()

{

 // Show info

 GUI.Label (Rect (10, 10, 150, 25), "pos : " + rigidbody.position);

 GUI.Label (Rect (10, 30, 150, 25), "velocity : " + rigidbody.velocity);

 GUI.Label (Rect (10, 50, 150, 25), "speed : " + rigidbody.velocity.magnitude);

 GUI.Label (Rect (10, 70, 150, 25), "dist : " + dist.magnitude); // dist = player.transform.position - transform.position;

 GUI.Label (Rect (10, 90, 150, 25), "ang : " + transform.rotation.eulerAngles);


}

so there may be a way ins$$anonymous$$d of rigidbody's :

http://unity3d.com/support/documentation/ScriptReference/Vector2.html

scroll down to Class Functions.

avatar image Berenger · Jan 28, 2012 at 07:20 AM 0
Share

You could use Rect and the Contains function. Not much of a difference, but better have too many options than not enough isn't it ?

0 Replies

· Add your reply
  • Sort: 

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

C# Convert Vector3[] to Vector2[] 3 Answers

Create custom constructors for certain Value types/Objects (Vector3, Transform, etc...) 2 Answers

[HELP] Translating vector 2 co-ordinates to real space 1 Answer

Transfer values from C# to Javascript 1 Answer

how to find a point(vector2) between two points(Vector2) of a line (line renderer) 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