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 samqweqwe · Jul 28, 2014 at 11:14 PM · raycasthitradiusmagnitudenormalize

Getting the radius of a square

Hi, i am trying to get the radius of a square so that an object can be placed a certain distance away from the square. I have this but it does not work:

 Vector3 differenceFromCenter = hit.point - hit.transform.position;
 Vector3 SecondPoint = hit.transform.position + (differenceFromCenter.normalized * (differenceFromCenter.magnitude+distance));

  

where hit is a RaycastHit which hits the square and distance is added distance away from the square. How can this be done?

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

Answer by TeoL · Jul 29, 2014 at 12:24 AM

Could you do something like this?

 Vector3 locationToPlaceObject;
 Vector3 distance = new Vector3(10,0,0);
 Vector3 objectEdge = hit.transform.position - hit.transform.bounds.extents;
 
 locationToPlaceObject = objectEdge - distance;
Comment
Add comment · Show 1 · 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 samqweqwe · Jul 29, 2014 at 12:50 AM 0
Share

Would that would on the if the ray hit the bottom or top of the cube?

avatar image
0

Answer by VesuvianPrime · Jul 29, 2014 at 12:05 AM

How are you calculating distance at the moment?

There are a number of different ways you can get the dimensions of your hit object, varying in accuracy:

1) Assuming the object is a perfect Cube you can take the lossyScale/localScale of the transform as its world dimensions (e.g scale 10x10x10 would be a cube of side 10).

2) Since you're using rays already, we can take the collider of the target GameObject and look at the bounding box for dimensions.

3) You could even get the MeshFilter from the target GameObject and get the bounds from the Mesh

Comment
Add comment · Show 1 · 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 samqweqwe · Jul 29, 2014 at 12:36 AM 0
Share

The Distance is a fixed value, for example: 1. I forgot to mention that in the question. What i am trying to achieve is to position an object a distance away from the cube. If the distance is 1, it would be 1 distance from the cube, not the position of the gameobject. There is an image of what i am trying to explain. The red line shows the points in which an object could be created. If a ray hits the cube at "X" from the right then the object would be positioned at "Y". hope this explains it better!alt text

radius of a square.jpg (19.3 kB)

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

magnitude normalize help 1 Answer

Jumping problem to do with /= magnitude changing the vector3 direction 1 Answer

Problems with diagonal movement. 1 Answer

getting the radius of a capsule collider 1 Answer

radiusX and radiusY ? 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