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 Archonn · Nov 25, 2012 at 11:15 PM · collidercubeedge

Edge of a cube

Given a cube of scale 2,1,1, and without knowing its rotation, i want to find where its right-most point is.

So the distance from the center to its right will be further if its flat, compared to if its standing up.

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

Answer by aldonaletto · Nov 26, 2012 at 01:09 AM

You could get the mesh vertices, convert to world coordinates and then to the camera local space to find the one with greatest X coordinate - like this:

 function FindRightmostPoint(obj: GameObject): Vector3 {
   var mesh: Mesh = GetComponent(MeshFilter).mesh;
   var verts: Vector3[] = mesh.vertices; // get cube vertices
   var xMax: float = Mathf.NegativeInfinity;
   var pMax: Vector3;
   for (var vert: Vector3 in verts){
     // get vertex in world coordinates:
     var worldP = obj.transform.TransformPoint(vert);
     // convert to camera's local coordinates:
     var localP = transform.InverseTransformPoint(worldP);
     if (localP.x > xMax){
       xMax = localP.x;
       pMax = worldP;
     }
   }
   // return world coordinates of rightmost vertex:
   return pMax;
 }

This function should be placed in a camera script: it finds the rightmost vertex of the object obj from the camera's point of view, and return it in world coordinates.

Comment
Add comment · Show 3 · 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 Archonn · Nov 26, 2012 at 10:37 AM 0
Share

var localP = transform.InverseTransformPoint(p);

What is p? You dont have another reference to it. Is it worldP?

avatar image aldonaletto · Nov 27, 2012 at 03:52 AM 0
Share

$$anonymous$$y bad: it should be worldP - answer fixed now.

avatar image yoonkuu · Nov 29, 2012 at 11:07 AM 0
Share

I'm yoonkuu... Tryin to find a way to contact you. Can you make this for me?? What's your email?? comment below so that i can check your answer? Thanks I have ragespline and all the other stuff, but don't know how to make this kinda object.. Can u tell me your email so that i can send you What i worked on? and you can look up here for the code.. http://forum.unity3d.com/threads/54092-Draw-Polygon Can u implement it for me/?? I really need to make that cube.. Here's a much more depth look at it http://www.youtube.com/watch?v=g7zTm$$anonymous$$vvUpk At some mark, it shows the ragecube thing.

avatar image
1

Answer by Bunny83 · Nov 25, 2012 at 11:34 PM

What "right" are you talking about? The positive x axis in worldspace? If so you can simply use:

renderer.bounds.max.x

otherwise be more specific.

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 Archonn · Nov 25, 2012 at 11:47 PM 0
Share

I should have said, what appears to be right relative to the camera.

avatar image Bunny83 · Nov 26, 2012 at 10:54 AM 0
Share

That's something totally different :)

Now it depends on if you use a perspective camera (this is very hard) or an orthographic camera (not that hard).

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

Weird Collision Detection with a Cube and OnCollisionEnter 2 Answers

Why would my floor suddenly disappear upon play? 1 Answer

Enable gravity of a clone on MouseUp? 1 Answer

Sphere clipping in cube 1 Answer

Collider on an empty object or a cube? 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