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 yyamiyyugi · Aug 20, 2013 at 12:58 PM · c#rotationrotate object

Rotating an object

Hello Unity Answers, I am trying to create a script to rotate my model as I turn. I got some code from Here And it works great after changing the rotation to the Y axis except the fact that it returns the rotation to 0, 0, 0. Is there a way I can edit it to where the return position is 0, 90, 0? I tried adding an if statement for turning the model then an else statement to set it to 0, 90, 0

Edit: Here is the code I have, it's essentially the same as linked above

 public float smooth = 2.0F;
     public float tiltAngle = 30.0F;
     void Update() {
 
         float tiltAroundY = Input.GetAxis("Horizontal") * tiltAngle;
         Quaternion target = Quaternion.Euler(0, TiltAroundY, 0);
         transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth);
     }
Comment
Add comment · Show 9
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 Joyrider · Aug 20, 2013 at 01:02 PM 0
Share

1/ Tag your question correctly... you're on unity answers so the tag unityanswer has no meaning. You should have at least set rotate.

2/ what do you mean exactly with >> " it returns the rotation to 0, 0, 0". Edit your question with a formatted excerpt of your code where you are trying to do this.

avatar image jg2115 · Aug 20, 2013 at 03:19 PM 0
Share

I retagged it.

avatar image ActionAbbas · Aug 20, 2013 at 03:30 PM 0
Share

Hi, could you edit your question and post the code for your script in the question.

avatar image yyamiyyugi · Aug 20, 2013 at 04:56 PM 0
Share

I edited the post with the code

avatar image ActionAbbas · Aug 20, 2013 at 05:07 PM 0
Share

Have you tried changing the public float tiltAngle

Show more comments

3 Replies

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

Answer by chelnok · Aug 20, 2013 at 11:56 PM

Add 90 degrees to default angle: Quaternion.Euler(0, tiltAroundY +90, 0);

 public float smooth = 2.0F;
     public float tiltAngle = 30.0F;
     void Update() {
  
         float tiltAroundY = Input.GetAxis("Horizontal") * tiltAngle;
         Quaternion target = Quaternion.Euler(0, tiltAroundY +90, 0);
         transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth);
     }

..or make empty gameobject as parent and current gameobject as child with (0,90,0) rotation. Rotate parent.

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 yyamiyyugi · Aug 21, 2013 at 01:31 AM 0
Share

This worked perfectly, Thank you for the help

avatar image
0

Answer by ActionAbbas · Aug 20, 2013 at 07:38 PM

Hi, ok this is a quick answer but this is significant.

"Quaternion target = Quaternion.Euler(0, TiltAroundY, 0);"

Comment
Add comment · Show 5 · 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 yyamiyyugi · Aug 20, 2013 at 08:15 PM 0
Share

What? I don't get what you mean, thats exactly what i have up there

avatar image Joyrider · Aug 20, 2013 at 09:13 PM 1
Share

hehe @ActionAbbas... even if you give a quick answer, you could have added what was wrong with that line :)

@yyamiyyugi , you have capital T to tiltAroundY in your Quaternion line, but not in your variable definition

avatar image yyamiyyugi · Aug 20, 2013 at 09:45 PM 0
Share

Thats not it, in my code thats fixed, the issue is not that it isn't rotating it's that when it goes back into position it goes to (0,0,0) ins$$anonymous$$d of (0,90,0) like I need.

avatar image ActionAbbas · Aug 20, 2013 at 10:33 PM 0
Share

so if it's not that, then how about rotating the actual object 90 degrees in the editor? $$anonymous$$aybe that's it.

@Joyrider yeah I should have explained. :-)

avatar image yyamiyyugi · Aug 21, 2013 at 01:34 AM 0
Share

It Was rotated to (0, 90, 0) in the editor but my code was making it rotate back to (0, 0, 0) when it was running, all i had to do was change (0, tiltAroundY, 0) to (0, tiltAroundY + 90, 0)

avatar image
0

Answer by moghes · Aug 20, 2013 at 09:20 PM

try this,

 //or use a FixedUpdate 
 void Update () 
 {
    private float horiz = Input.GetAxis("Horizontal") * tiltAngle;
    transform.Rotate(new Vector3(0,horiz ,0), Space.Self);
 }
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 yyamiyyugi · Aug 20, 2013 at 09:51 PM 0
Share

All that did was make it spin rapidly, did't even unrotate its self when I was done turning like my original does

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

19 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

Related Questions

Flip over an object (smooth transition) 3 Answers

Face Direction Movement using CharacterController 1 Answer

Distribute terrain in zones 3 Answers

problem after rotate an object 0 Answers

Why the player is not rotating and moving at the same time ? 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