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 JeffreyRef · Mar 10, 2013 at 08:05 PM · transformswitchresetswitching

switch controlling transform

Hello everyone, I'd like to ask for help with a little issue

I'm having. What I'm trying to do is have a script that will rotate an

object based on mouse input. I'd also want to switch the

transform I'm doing the rotation on to a different object's

during run time. I'm having an issue with my script, when I press the button to

switch to another object's transform, it works fine. but when I press button to go back to the previous transform,

it's X rotation is immediately changed to 90.:confused: This

also happens if let's say I'm on object 1 and I press key to go

to object 1. I've been looking over this for a while now, I'm just not sure

what I'm doing wrong. Thank you in advance !!

 public class TestRotateSwitch : MonoBehaviour 
 {
     public Transform transCur;
     public Transform ref1;
     public Transform ref2;
     
     private float xrot;
     private float xRotCur;
     public float xrotspeed;
     private float _ref_X_Velocity;
     
     
     private float yrot;
     private float yRotCur;
     public float yRotSpeed;
     private float _ref_Y_Velocity;
     
     
     
     void Start () 
     {
      transCur = ref1;
     }
     
     void Update () 
     {
         if(Input.GetKeyUp (KeyCode.Q))
         {
             yrot = ref1.rotation.eulerAngles.y;
             xrot = ref1.rotation.eulerAngles.x;
             yRotCur = yrot;
             xRotCur = xrot;
              transCur = ref1;
             transCur.rotation = ref1.rotation;
             
         }
         if(Input.GetKeyUp (KeyCode.E))
         {
             yrot = ref2.rotation.eulerAngles.y;
             xrot = ref2.rotation.eulerAngles.x;
             yRotCur = yrot;
             xRotCur = xrot;
             transCur = ref2;
         }
      yrot += yRotSpeed * Time.deltaTime * Input.GetAxis 
 
 ("Mouse X");//InputManager_IG.MovingStick.StickPosition.x ;
         
         xrot -= xrotspeed * Time.deltaTime * 
 
 Input.GetAxis ("Mouse 
 
 Y");//InputManager_IG.MovingStick.StickPosition.y ;
         
         xrot = Mathf.Clamp (xrot,-90,90);
         
         yRotCur = Mathf.SmoothDamp (yRotCur,yrot, ref 
 
 _ref_Y_Velocity,0.000001f);
         
         xRotCur = Mathf.SmoothDamp (xRotCur,xrot, ref 
 
 _ref_X_Velocity,0.000001f);
         
         transCur.rotation = Quaternion.Euler (new 
 
 Vector3(xRotCur,yRotCur,0));
     }
 }
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

0 Replies

· Add your reply
  • Sort: 

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

10 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

Related Questions

how to reset a transform.rotate 1 Answer

switch character 1 Answer

transform.localPosition problem. 0 Answers

Resetting a gameobjects position? 1 Answer

Error With Switching Characters 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