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 PaxStyle · Jul 03, 2014 at 12:39 PM · objectmove

How can I move a corresponding object.

Hi, how can I move an object up and down in correspondence of the another object? Which is the easier way? Someone told me that I can use the same code also for both object, but I tried and this did not work.

Thank you in advance

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 PaxStyle · Jul 04, 2014 at 03:09 PM 0
Share

Up . . . ;)

avatar image meat5000 ♦ · Jul 04, 2014 at 03:53 PM 0
Share

Off Topic :

@PaxStyle Friendly re$$anonymous$$der, please go through your 98 questions and Accept any correct answers by clicking the tick. When someone has taken the time to help you and the solution has worked, its the polite thing to do :)

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Mediamonkey · Sep 15, 2014 at 01:25 PM

piston example

I added this script to the two parts that make up the piston. The hinge for the top of the piston is located on an arm, but is optional for the body of the piston. The sliding top of the piston contains the same script and the lookAtTarget is each others transform.

I added a rotationOffset so both pieces don't need to initially point in the correct direction (forward).

Now if you move the arm, the piston will move correctly. It is possible that it overshoots, but that is the animator's choice.

 using UnityEngine;
 using System.Collections;
 
 public class SimplePiston : MonoBehaviour {
 
     public Transform hinge;
     public Transform lookAtTarget;
     public Vector3 rotationOffset;
 
     protected Transform tf;
 
     void Start() {
         tf = transform;
     }
 
     void Update () {
         if (hinge != null) tf.position = hinge.position;
         tf.LookAt(lookAtTarget);
         tf.Rotate(rotationOffset);
     }
 }



piston.png (101.2 kB)
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
avatar image
0

Answer by Juice-Tin · Jul 04, 2014 at 08:05 PM

Easy solution with perfect outcome:

 1. Attach the actual piston to the pink arm (make sure the pistons center is at the tip where it touches the arm)
 
 2. Put script on the piston transform.LookAt(pistonHolder);
 
 3. Put script on that piston holder transform.LookAt(piston);
 
 4. Celebrate the perfect piston mechanics!

This will attach your piston to the arm, and because the piston and piston holder are looking at each other, they will slide into each other perfectly. Note you may need to put them in parent objects to make sure they're aligned properly and facing the right direction.

Comment
Add comment · Show 3 · 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 PaxStyle · Jul 05, 2014 at 04:09 PM 0
Share

I tried this, I created 2 empty game object positioned near the piston and the piston holder, and i put them into the new game objects. I put this code for both, as you said, but when i press play, the position are all wrong. Ah, the piston holder should not move, so I don't drag the code into it. is not correct my steps?

 using UnityEngine;
 using System.Collections;
 
 public class Piston : $$anonymous$$onoBehaviour {
     public Transform target;
     void Update() {
         transform.LookAt(target);
     }
 }
avatar image PaxStyle · Jul 08, 2014 at 06:00 PM 0
Share

Hey? . . .

avatar image PaxStyle · Jul 10, 2014 at 03:18 PM 0
Share

Someone can help me? thanks!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

using Transform on a Object will not move it 100% exactly... 1 Answer

Editor like spore? (move object on other object) C# 0 Answers

What am I doing wrong? 1 Answer

Rotate object with another object 0 Answers

Move another cube with a cube 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