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 /
  • Help Room /
avatar image
0
Question by Ahapid · May 09, 2017 at 04:54 PM · transformrotate

Rotor script (rotation into the - values)

so, i got this script and want to make a object rotate around the z axis till a certain point is reached. the script does that perfectly well, but now i want to make it able to rotate into the -degrees, how could i do that?

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Rotor : MonoBehaviour {

 public float MaxAngle;
 public float MinAngle;
 public float speed;
 public KeyCode upKey;
 public KeyCode downKey;
 GameObject ObjectToRotate;

 // Use this for initialization
 void Start () {
     ObjectToRotate = transform.GetChild(0).gameObject;
 }
 
 // Update is called once per frame
 void Update () {
     if (Input.GetKey(upKey) && MaxAngle > transform.GetChild(0).eulerAngles.z && MaxAngle > 0)
     {
         transform.GetChild(0).Rotate(Vector3.forward);

     }



     if (Input.GetKey(downKey) && MinAngle < transform.GetChild(0).eulerAngles.z && MinAngle > 0)
     {
         transform.GetChild(0).Rotate(Vector3.forward);

     }
 }

}

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

1 Reply

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

Answer by brett_ridel · May 09, 2017 at 05:14 PM

According to the documentation (https://docs.unity3d.com/ScriptReference/Transform.Rotate.html), the Vector3.forward parameter is not the axis but the euler angle.

public void Rotate(Vector3 eulerAngles, Space relativeTo = Space.Self);

I say it because I'm not sure this is what you want to do. If so, you can just invert the Euler angle : Rotate(-Vector3.forward)

You can also use the Transform.Rotate version that allows you to specify both the axis and the angle

public void Rotate(Vector3 axis, float angle, Space relativeTo = Space.Self);

With this version, you just have to set the axis as Vector3.forward, and put a positive or negative value for the angle.

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 Ahapid · May 09, 2017 at 06:53 PM 0
Share

the problem is, that if the rotation goes over 180 degrees, it switches to $$anonymous$$us which messes up the limitations.

avatar image brett_ridel Ahapid · May 10, 2017 at 09:53 AM 0
Share

$$anonymous$$aybe you should think differently the conditions when you want to rotate. What exactly do you want to do ? Do you want to rotate in one way when the up key is pressed, and rotate in the other way when the key down is pressed ? If so, what is the $$anonymous$$axAngle and $$anonymous$$inAngle use for ?

avatar image Ahapid brett_ridel · May 10, 2017 at 02:38 PM 0
Share

yes, exactly that.

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

113 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

when trying to rotate, the object transforming itself 0 Answers

Rotating an object with VR controller 1 Answer

Move Single Bone With Script? 0 Answers

Cant stop object/ridgidbody from rotating 2 Answers

Rotation speed of the player (Paper Mario like) 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