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
0
Question by oliver-jones · Oct 15, 2015 at 11:38 AM · raycasttransformaxisparent-childlocalposition

Move Parent Along Childs Local Axis

I'm building a 3D puzzle in which the camera rotates around the puzzle on a central axis. I want to be able to move the pieces relevant to the camera direction only on X and Y.

The piece has a plane within it as a child. This plane is always facing the camera, this plane is what detects the Raycast. I want to be able to move the piece along the plane axis on X and Y.

Below as an image of the piece selected (I'm looking through the game camera), and as you can see, the axis is incorrect for the movement of X and Y relevant to the camera. The purple plane is the plane I mentioned above, it always faces the camera.

alt text

As you can see, when I select the plane, the axis is correct. So I need to somehow move the piece (plane's parent), along this axis only on X and Y.

alt text

How can I achieve this? The raycast update is called like this on the puzzle piece:

 //hitPoint is the location of the raycast on PLANE
 function UpdatePiecePosition(hitPoint : Vector3){
 
     //right now - I'm just doing a general position
     //raycast plane is moved as well as its a child - this is fine
     transform.position = hitPoint;
 
     //update planes rotation to camera
     plane.transform.LookAt(cam.transform);
 }

screen-shot-2015-10-15-at-122122.png (46.6 kB)
screen-shot-2015-10-15-at-122130.png (41.8 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by DiegoSLTS · Oct 15, 2015 at 01:32 PM

Check the Transform.TransformDirection and Transform.InverseTransformDirection methods. You can get, say, the transform.right of the plane (which returns the right direction in local space):

 Vector3 right = plane.transform.right;

... trasform that direction into a world space direction:

 right = plane.transform.TransformDirection(right);

... and then transform that direction into the local space of the parent game object:

 right = theParentObject.transform.InverseTransformDirection(right);

You can now move the object in that direction.

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 oliver-jones · Oct 15, 2015 at 01:38 PM 0
Share

Thanks. Why would I want the right direction though? The direction of the plane changes depending on the axis of the camera that rotates around the 3D puzzle.

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

31 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

Related Questions

Error in localPosition 1 Answer

calculating my position from another object 1 Answer

Locking gameobject to rotating floor 0 Answers

Unity Character Controller messing up. 0 Answers

GameObject position and localPosition not changing in hiearchy, only in script. 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