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 /
  • Help Room /
avatar image
0
Question by qtoompuu · Sep 02, 2016 at 04:59 PM · transformvector3distance

InverseTransformPoint() help

I am making a script for the HTC VIVE. In my script, i am trying to find the distance between two points on an objects local axis and use this value to set the position of another object. I am attempting to achieve this using the InverseTransformPoint() function to get the distance. The current setup is as follows

I have an object(we will call object1) and childed on that object are point a and point b. Point a is static,and is the point from which I am measuring the distance. point b is what I am trying to set based off of the distance measured. I am using the vive controller as the last point(point c) and it is the second point in the distance calculation

so in theory what I want to have happen is, on a local scale i want the distance between point c (not a child of object1) and point a (is a child) to be measured; then using that measurement I want point b to be set that distance away from point a. thus setting it where the controller is but in the local space of object1.

the issue I am running into is that the point b is getting set 3.47 times further than it should which I think is due to the distance being calculated on the wrong scale. as a temporary fix I just divided by 3.47, but I'm trying to make the system reusable, and having to manually calculate this offset every time would be tedious. The code I am using is as follows:

 //calculating the distance between c and a
 controllerDistance = (object1.InverseTransformPoint(pointa.position).z - object1.InverseTransformPoint(pointc.position).z);

later in the code

 //offset should = the direction and magnitude point b needs to move
 offset = Quaternion.AngleAxis(pointa.transform.rotation.y, pointa.transform.up) * pointa.transform.forward * (controllerDistance);
 pointb.position = pointa.transform.position + offset;

please help me out I've been stuck on this for days now

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 villevli · Sep 02, 2016 at 08:29 PM 0
Share

setting it where the controller is but in the local space of object1

If pointb is child of object1, you can just: pointb.localPosition = pointc.positionIf pointc is the controller in worldspace.

avatar image qtoompuu villevli · Sep 02, 2016 at 10:33 PM 0
Share

That was my first attempt, but sadly since the object1's rotation is constantly changing, I needed to use the method outlined above to account for that. setting the pos as you have outlined gives me different positions for the same distance depending on the objects rotation. all I really need to figure out is what is causing the distance to be increased by the 3.74 that it is

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

79 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

Related Questions

Don't trust "Vector3.Distance"? 1 Answer

How would someone go about creating multiple triggers in one script 0 Answers

Transform.position not working- want to clamp object within confines of screen 0 Answers

Move GameObject to Point A to B 1 Answer

Object to walk forward, turn 180 and walk back 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