• 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 blitzen · Sep 30, 2011 at 09:53 AM · worldaccuratetransform.transformpoint

Consistent World Transformation of Collider Point

I'm trying to get accurate world coordinates for a certain local point of an object's box collider (say, the bottom rear right corner when facing +z). I've used the following implementation in a script attached to the object:

 var pos:Vector3=transform.TransformPoint(
         Vector3.right*collider.bounds.extents.x+
         Vector3.down*collider.bounds.extents.y+
         Vector3.back*collider.bounds.extents.z);

This places it pretty close to where I'd expect, when the object is facing forward; however, when I turn it to the side in the game (rotate it left by the Y axis), the point that this returns bows outward, a good 20% or so outside the collider, making the particles I'm spewing from it leave widening and narrowing trails. Do you know what's going on, and how to keep it more consistently accurate no matter the transform's orientation?

Comment
Add comment · Show 1
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 blitzen · Oct 01, 2011 at 03:06 AM 0
Share

According to another post, collider.bounds.extents gives real-world coordinates, which if it doesn't take into account the box's rotation, might widen and shorten as it rotates to account for the corners and straights with respect to a camera. That might be an explanation.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by aldonaletto · Oct 01, 2011 at 03:31 AM

You're right: bounds is a AABB - Axis Aligned Bounding Box - so it doesn't rotate with the object, as you've already found. A simple way to avoid this problem is to get these dimensions at Start: make sure the object has zero initial rotation and save the extents in some variable.

private var ext: Vector3;

function Start(){ var rot = transform.rotation; // zero the rotation, if needed transform.rotation = Quaternion.identity; ext = collider.bounds.extents; // save the extents transform.rotation = rot; // restore the rotation }

// you can calculate the points you need in a simpler way: var rearPoint = transform.TransformPoint(0, -ext.y, -ext.z); var bottomPoint = transform.TransformPoint(0, -ext.y, 0); var frontPoint = transform.TransformPoint(0, 0, ext.z);

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Unity Editor moving slow(Not CPU wise, but slow speed wise). 3 Answers

Block world Generator 0 Answers

how do i make a script that records where a player was before entering another room 0 Answers

Translate Vector3 by Vector3 1 Answer

How to move the character relative to the camera? 0 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