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
1
Question by Bentoon · Jun 27, 2016 at 05:01 AM · vrtransform.positionparent-child

Parenting a child to move on only one Axis !

Hello hello

I am parenting a child to move on only one of it's axis while the parent moves on all three...

I have an unwieldy paddle in my game, when I touch the child object and pull a trigger, I only want the child to move only up and down on it's own Y axis. While my parent paddle is moving loosely in all directions, it only effects the child's Y

    void OnTriggerStay (Collider col)
     {
 
 // Both the child and Parent have colliders 
 // When I contact  but the object together and press button :
 
         if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger))
         {
             col.attachedRigidbody.isKinematic = true;
 //  I need something like col.gameObject.transform.position.y = parent.gameObject.transform.position.y;
 // or
 //  col.gameObject.transform.SetParent(gameObject.transform.y );
         }
 
         if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger))
         {
             col.gameObject.transform.SetParent(null);
             col.attachedRigidbody.isKinematic = false;
         }
 
 

Any ideas? Thanks ~be

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
1

Answer by Dibbie · Jun 27, 2016 at 06:13 AM

Where you have your comments in Line 10, replace it with this kind of idea:

 Vector3 limitedPaddle = col.gameObject.transform.position; //get the current position of your object you want to move up and down, im assuming thats the "col" object.
 
 //limitedPaddle.y = //howeverYouWantToManipulateTheYAxis;
 //Only y will be affected this way.
 
 col.gameObject.transform.position = limitedPaddle; //Now you are applying the full Vector3/Position to this object, but since you never changed X and Z, they stay the same, and only Y was changed, therefore, only Y updates on the object when you apply/set the objects position to 'LimitedPaddle'.

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 Bentoon · Jun 27, 2016 at 05:06 PM 0
Share

Excellent ! I definitely need to finesse (as I am in VR) but this was exactly what I was looking for !

Thank you!

~be

avatar image
0

Answer by $$anonymous$$ · Jun 27, 2016 at 07:03 AM

Do the objects need to be parented? If not:

 public class ObjectTracker : MonoBehaviour 
 {
     GameObject target = null;
 
     bool triggerDown, triggerStay, triggerUp;
     
     // Update is called once per frame
     void Update () 
     {
         //Checks if the trigger is down and the target is currently within range
         //Replace with your own controller code
         if(triggerStay && target != null) 
         {
             //Changes only the y position of the transform to match the target
             //Possibly replace this with a Mathf.Lerp for a better effect
             transform.position.y = target.transform.position.y;
         }
     }
    
     //On Collision Enter assigns the target once it is in range
     //Add any other platform initialization code here
     void OnCollisionEnter(collision col) {
         target = col.gameobject;
     }
 
     //On Collision Exit removes the target when out of range
     //Add any other platform deactivation code here
     void OnCollisionExit(collision col) {
         if (target == col.gameobject)
             target = null;
     }
 }

If you need to move the object with physics replace transform.position.y = target.transform.position.y; with rigidbody.MovePosition() instead.

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 Bentoon · Jun 27, 2016 at 05:08 PM 0
Share

Nice! Thank you

This may be the way to go, in the future if Parenting won't work

Thanks!

~be

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

54 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

Related Questions

Unity Object Aligment in Different Resolutions and Scales 0 Answers

One child object move differently as 0.0001f when moving parent 1 Answer

How to transform position of object A to object C (C is a child of B object) 1 Answer

Cardboard VR: Drag object towards player but have it stop just before 0 Answers

How to make throwable child object? 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