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 mustang4484 · Jan 12, 2019 at 06:43 PM · rotatetranslate

Rotation follow translation

Hi guys

I would like to make an object that rotates on the y axis based on the translation (not rotation) of another object on the x axis.

Something can help me?

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 Magso · Jan 12, 2019 at 09:00 PM 0
Share

Do you mean based on the position or translation of the other object?

avatar image sean244 · Jan 13, 2019 at 06:39 AM 0
Share

Can you show a video or animation of what you're talking about?

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by DCordoba · Jan 13, 2019 at 10:00 AM

well after remembering a bit of math, here we go; Iam not sure if diff get the correct distance, the rest is geometry and the transform.Rotate function:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class BasicTrack : MonoBehaviour {
     public Transform TargetObject; //set it on inspector
     public float Angle = Mathf.PI ;//proportional rotation of the second object, default is the same angular translation at diameter 1, multiply by 2 radius to change angular rotation
     float StartPoint = 0;
     float diff; //reusable variable, distance from current x position to previous
 
     void Start () {
         StartPoint = TargetObject.position.x;
     }
     // FixedUpdate is use by physics
     void FixedUpdate () {
         //this if really not work with floats, use a aproximate comparision like Mathf.Abs(Mathf.Abs(StartPoint)-Mathf.Abs(TargetObject.x))<0.01f
         if (StartPoint != TargetObject.position.x) {
             //PI*radius*2 is the distance that a wheel do on a single rotation
             diff = TargetObject.position.x-StartPoint;
             transform.Rotate (Vector3.up, (360/Angle)*diff); 
             StartPoint = TargetObject.position.x;
         }
     }
 }

of course the script will be attached to the object that rotate, the TargetObject is the object moving along the x.

Edited @mustang4484 eliminating the last Mathf.Absu have a unclamped rotation at two directions, to do inverse clockwise replace transform.Rotate (Vector3.up, (360/Angle)*diff); with transform.Rotate (-Vector3.up, (360/Angle)*diff); (note the minus...)

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 mustang4484 · Jan 13, 2019 at 11:13 AM

alt text

Thank you all, I explained myself badly. I would like that when my Object P move on the right (B) my arrow turn to (B) with degree proportional to start position-b.

It's a similar to @DCordoba but with the inverse clockwise if the player go to -x.

Thank you


unity-question.jpg (216.5 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 Magso · Jan 13, 2019 at 12:03 PM

If you have a variable for the rotation then you can do something like this,

 float currentRotation, timesDifference, maxAmount;
 
 void Update(){
     transform.eulerAngles.y = currentRotation;
     other.transform.position.x = currentRotation * timesDifference;
     currentRotation = Mathf.Clamp(currentRotation, -maxAmount, maxAmount)
 }

edit: I've just noticed A and B are going in opposite directions.

 other.transform.position.x = -currentRotation * timesDifference;
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.

Follow this Question

Answers Answers and Comments

102 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 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

Translate and rotate at the sametime problem 1 Answer

Airplane stalls when flying straight up/down 1 Answer

Boat moving forward while rotating towards point 1 Answer

Infinite Moving/Rotating Question 1 Answer

Parenting without transform.rotation 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