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 LastTemplar · Oct 28, 2011 at 09:42 PM · rotationtransform

Transform rotation

Hi, I have a problem with the transform.rotation. I want one object to repeat an other object's rotations, but not completely, I need the rotation on the y Axis to be modified. This is what I have right now

 rotx = GameObject.FindWithTag("knee").transform.rotation.x;
 roty = GameObject.FindWithTag("knee").transform.rotation.y;
 rotz = GameObject.FindWithTag("knee").transform.rotation.z;
 //print(rotx + " " + roty + " " + rotz);
 this.transform.rotation = GameObject.FindWithTag("knee").transform.rotation;

So, this code works great right now, I need to modify it in some way as to apply each axis rotation individually, what I would like it to look like is something like this

 this.transform.rotation.x = rotx;
 this.transform.rotation.y = roty;
 this.transform.rotation.z = rotz;

Is this possible to achieve in any way?

Thanks ;)

Comment
Add comment · Show 1
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 LastTemplar · Oct 29, 2011 at 12:59 AM 0
Share

Ok, I tried a bunch of other things, nothing made me happy. I almost found a solution to satisfy my needs though:

Vector3 pivotPoint = new Vector3(0,0,0);

pivotPoint = GameObject.FindWithTag("follower").transform.position;

this.transform.RotateAround(pivotPoint, Vector3.right, y);

So this rotates the object just as I need it to rotate. But I need another type of function, I don't want to input the Amount for the object to rotate, I need my object to rotate until a certain value, could someone help me here? I'm kind of running out of ideas :/

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by SinisterSound · Oct 28, 2011 at 10:42 PM

Yes, but you will have to store them in a temporary variable or create one on the fly when setting your new rotation.

Instead of:

 this.transform.rotation = GameObject.FindWithTag("knee").transform.rotation;

You should do:

 this.transform.rotation = new Quaternion(rotx, roty, rotz, rotw);

From there you can modify any of the passed in parameters as you please :)

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
2

Answer by Rod-Green · Oct 28, 2011 at 11:25 PM

Another way is to store the current Rotation value and modify as needed and then finally reapply at the end of the method i.e.

 Quaternion curRotation = this.transform.rotation;
 // Order is important!! A rotation that rotates euler.z degrees around the z axis, euler.x degrees around the x axis, and euler.y degrees around the y axis (in that order).
 curRotation.eulearAngles.z += rotz;
 curRotation.eulearAngles.x += rotx;
 curRotation.eulearAngles.y += roty;
 this.transform.rotation = curRotation;


In your case though it can be simplified to basically:

 using UnityEngine;
 using System.Collections;
 
 public class RotateScript : MonoBehaviour
 {
 
     public Transform otherTrans;
 
     void Start()
     {
         if(otherTrans == null)
         {
             enabled = false;
             return;
         }
         
     }
 
 
     void Update()
     {
         
         float rotx = otherTrans.rotation.eulerAngles.x;
         float roty = otherTrans.rotation.eulerAngles.y;
         float rotz = otherTrans.rotation.eulerAngles.z;
         //print(rotx + " " + roty + " " + rotz);
         
         // Tweak roty in some way -- i.e.
         roty = 0.0f;
         
         //Then apply the new values
         this.transform.rotation = Quaternion.Euler(rotx, roty, rotz);
     }
 }
Comment
Add comment · Show 4 · 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 LastTemplar · Oct 28, 2011 at 11:46 PM 0
Share

Your solution skews the model in a very strange way :/

avatar image Rod-Green · Oct 29, 2011 at 01:24 AM 0
Share

There's no skewing in my code (though I failed to include .eulerAngles prop) however are you doing other transforms also? i.e. non uniform scaling? I think you should add a longer example of the code you're having trouble with. This might help people try and provide a solution.

  • edited to give a more complete example

avatar image LastTemplar · Oct 29, 2011 at 01:43 AM 0
Share

After searching for some more solutions I now think I approached the question from a wrong angle. What I have is a human model (with parts as leg, hand, etc. attached) with an Animation attached to it (he bends his knee). I can go to the Animation window and look at the leg animation and modify the Rotate.y in there and everything works fine. Do you know how can I modify that value from a script?

avatar image Rod-Green · Oct 31, 2011 at 11:11 PM 0
Share

So if you just want to modify the Y rotation of an object via a script? Are you talking about editing animation data? or muting animation data and applying procedural data to an animation channel?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Rotation/position question. 1 Answer

Min-Angle Constraint Script Causes Jitter 0 Answers

A node in a childnode? 1 Answer

Smooth Y rotation based on X rotation (C#) 0 Answers

C# Need Help Refining Ricochet Script 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