Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by AltanZagas · Aug 15, 2019 at 03:10 PM · 2dplanevector2

How do i check if two objects are on the same 2D plane?

I dont know if the title makes sense, but i hope the pictures will.
I already know how to check on 1 axis. Now it triggers when the player is on the fictional dotted line.
alt text
Now I need to be able to check if the player is on the same "plane" as the object (the dotted line) even when the object is rotated.
alt text .
I basicly want to check this:
If you draw a line from the red object and its local up (dotted line). Is the player center on that line?
radius doesn't matter and line of sight doesn't matter.
The solution is probably very trivial, but I cant get my head around it atm.
Any help is much appreciated :)
Edit:
I found out that subtracting the two positions is better. Object.position.x - Player.position.x This way I also know which side the player is on.

first.png (23.6 kB)
second.png (25.6 kB)
Comment
Add comment · Show 2
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 I_Am_Err00r · Aug 15, 2019 at 03:36 PM 0
Share

Is there a radius that you need to check? Do you need to have line of sight?


If you don't need line of sight, a Physics2D.OverlapCircl:

 Physics2D.OverlapCircle(player.transform.position, float circleRadius, objectLayerReference)

I know you said you need to tell if it is rotated, maybe you could do something like this

 if(player.transform.position.x != object.transform.position.x)
 {
     objectIsRotated = true;
 }

By the way, in that example you show it is the x values that are same there, not the y.


I did not test any of that, I don't have access to Unity or a compiler to make sure I gave you 100% accurate info, so if there isn't something working for you, let me know and I'll see what I can do.

avatar image AltanZagas I_Am_Err00r · Aug 15, 2019 at 04:45 PM 0
Share

Hey, thanks for the response.
I think you misunderstood my problem (probably because of my bad description)^^.
I've updated the post, so hopefully it makes more sense now. I also fixed the first picture so that the if-statement is correct... ':D

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by sacredgeometry · Aug 16, 2019 at 08:55 PM

What you are talking about are coplanar/colinear vectors.

So you need to define a plane/line before you can find out if another vector sits on it.

Then you can calculate the triple product of the vectors. If you get 0, they are coplanar.

https://en.wikipedia.org/wiki/Triple_product

Example

 public static class Vector3Extensions
 {
     public static bool IsOnPlane(this Vector3 c, Vector3 a, Vector3 b) 
     {     
         return Vector3.Dot(a, Vector3.Cross(b, c)) == 0.0f;
     }
     public static bool IsInLine(this Vector3 c, Vector3 a, Vector3 b) 
     {     
         return Vector3.Cross((b-c), a-b) == Vector3.zero;
     }
 }
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

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

214 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 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image

Related Questions

2D collisions on a Texture2D with transparent areas 2 Answers

Having problems with mouse drag mesh vertex deformation 0 Answers

How to compare several distances? 1 Answer

2D game look at mouse rotate 1 Answer

2 fingers sprite rotation 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