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 Orangerlsy · Oct 27, 2016 at 08:11 AM · rotationrigidbodyaxiseulerangleseuler

Have angle problem in rigidbody.moveRotation

Hi, i'm using rigidbody.moveRotation for rotating my plane character. and i have 2 problems.

  1. It rotates well between 0 - 90, 270 - 0 degrees. but it doesn't rotate over that degrees.

  2. in vertical rotation, it doesn't work as local rotation. it works like default global axis.

following is my code.

 using UnityEngine;
 using System.Collections;
 
 public class PlayerMove : MonoBehaviour
 {
     
     public float speed = 10;
     public float rotationSpeed = 5;
 
     public float turnSpeed = 20;
 
     Vector3 dir;
 
     Rigidbody rig = null;
 
     float rotationX = 0;
     float rotationY = 0;
     float rotationZ = 0;
 
     Vector3 vectorX = Vector3.zero;
     Vector3 vectorY = Vector3.zero;
     Vector3 vectorZ = Vector3.zero;
 
 
     void Start ()
     {
            rig = transform.GetComponent<Rigidbody> ();
     }
 
 
     void Update ()
     {
         rotationY = Input.GetAxis ("Horizontal");
         rotationX = Input.GetAxis ("Vertical");
 
         rotationY *= Time.deltaTime * 50;
         rotationX *= Time.deltaTime * 50;
 
         vectorX = 
          new Vector3 (-rotationX, 0, 0) + new Vector3(transform.localEulerAngles.x, 0, 0);
 
         vectorY = 
          new Vector3 (0, rotationY, 0) + new Vector3(0, transform.localEulerAngles.y, 0);
 
         dir = vectorX + vectorY + vectorZ;
 
         print ("Angles " + transform.localEulerAngles);
     }
 
     void FixedUpdate() 
     {
         rig.MovePosition (transform.position + transform.forward * speed * Time.deltaTime);
         rig.MoveRotation (Quaternion.Euler(dir));
     }

 }

I really need help about this problem.

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 TreyH · Oct 27, 2016 at 11:03 AM 0
Share
 void Update ()
  {
      // You can change this to global and try that as well
      Vector3 currentEuler = transform.eulerAngles;
 
      // Increment these x/y values by your inputs
      currentEuler.x += Time.deltaTime * 50 * Input.GetAxis ("Horizontal");
      currentEuler.y += Time.deltaTime * 50 * Input.GetAxis ("Vertical");
 
      // Then just set this as our intended orientation for the next physics update
      dir = currentEuler;
 
     print ("Target Angles " + currentEuler);
  }

Your code is a bit long for what you're trying to accomplish. See if this simplifies things.

As for local, it shouldn't matter for your problem. You are getting its current angles (local or not) and assigning increments based on your input. You can set the Z back to zero if you want, but then again you could just lock that rotation altogether.

edit: It is worth noting that setting euler angles like this can potentially lead to issues down the road. There is a reason Unity stores its angles with Quaternions by default, allowing us to convert into the more traditional Euler angle system when convenient.

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

99 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

Related Questions

copy rotation script doesent copy the full 360 degrees? 0 Answers

Why does this quaternion euler not compute? 0 Answers

Draw a ray from a gamobject and keep direction of the ray relative to the gameobjects rotation. 1 Answer

How to calculate and use new direction angle as a new forward direction. 1 Answer

How to make a 2D sprite rotate towards a specific point while facing perpendicular to the camera ? 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