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 /
This question was closed Jan 06, 2018 at 07:53 PM by meat5000 for the following reason:

The question is answered

avatar image
0
Question by Deep96 · Jan 06, 2018 at 01:16 PM · rotationrigidbodyquaternion

I am having issues with rotating the player. I know this is simple but kindly have a look. You will be flabbergasted.

I am following Space Shooter tutorial and the player doesn't rotate but when I uncomment 'Debug.Log (rb.rotation);' the player starts rotating. I had implemented this game earlier on older version of unity and it worked. It seems that this issue is related to new version of unity. Also the player stays in rotated orientation when I hard code the angle

     private Rigidbody rb;
 public float speed;
 public float tilt;
 public Boundary boundary;

 // Use this for initialization
 void Start () {
     rb = GetComponent<Rigidbody> ();
 }

 void FixedUpdate(){
     float moveHorizontal = Input.GetAxis ("Horizontal");
     float moveVertical = Input.GetAxis ("Vertical");

     // move player
     Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
     rb.velocity = movement * speed;
     // restrict the player from going out of playing area
     transform.position = new Vector3 (
         Mathf.Clamp (transform.position.x, boundary.xMin, boundary.xMax),
         0.0f,
         Mathf.Clamp (transform.position.z, boundary.zMin, boundary.zMax)
     );

     // rotate the player based on velocity along X axis
     //Debug.Log (rb.rotation);
     rb.rotation = Quaternion.Euler (0.0f, 0.0f, rb.velocity.x * -tilt);
 }
Comment
Add comment · Show 3
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 pako · Jan 06, 2018 at 01:47 PM 0
Share

Have you followed the "Upgrade Guide to Unity 5", which can be downloaded from https://unity3d.com/learn/tutorials/s/space-shooter-tutorial ?

avatar image Deep96 pako · Jan 06, 2018 at 02:15 PM 0
Share

Thankyou so much. I appreciate your help. I had taken all annotations in the video into consideration. I just went through the 'upgrade guide' and the code is upto the mark. I am not using the code of the older version of unity rather I created the new project

avatar image Deep96 · Jan 06, 2018 at 02:26 PM 0
Share

I added following line before rb.rotation = Quaternion.Euler (); Quaternion rotation = rb.rotation; And guess what the player rotated

The above line makes no sense but what I figured out is that whenever I write a line that references 'rb.rotation' before rotating the object, the player rotates.

Is it because the 'rb.velocity.x' is not updated when the execution reaches the last line?

1 Reply

  • Sort: 
avatar image
0

Answer by meat5000 · Jan 06, 2018 at 02:48 PM

You are performing tasks in FixedUpdate which should be in Update... that is everything that is not directly Physics.

Debug.Log is intensive and is likely slowing things down enough for your FixedUpdate control method to actually be detected. I'm guessing, there's no other reason that I can think of that Debug.Log would affect things in this way.

This line from the docs may be key :

"If you change the rotation of a Rigidbody using Rigidbody.rotation, the transform will be updated after the next physics simulation step." So it could be just a timing issue.

Comment
Add comment · Show 2 · 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 Deep96 · Jan 06, 2018 at 04:01 PM 0
Share

@meat5000 I moved transform.position in Update() method and it worked 100 rewards for you Thanks, I really appreciate your help. But i couldn't find that line in docs. Doesn't matter I understood your explanation very well

avatar image meat5000 ♦ Deep96 · Jan 06, 2018 at 07:46 PM 0
Share

$$anonymous$$ost welcome. I added a link to the page in the answer for you. Seems to contain some other useful information.

Follow this Question

Answers Answers and Comments

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

Related Questions

Keep Rigidbody upright using torque. 1 Answer

Player rotates spastically on all axes when camera is turned 0 Answers

[VR] Rigidbody.AddForce() following controllers rotation 0 Answers

fromtorotation inacurate Help fixing? 0 Answers

How can I get a rigid body object to face in the direction my joystick is pointing smoothly? 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