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 Pwntheon · Feb 21, 2012 at 10:21 PM · rigidbodyquaternionchoppy

Choppy movement when rotating

I have an object that's flying. I am using mouse input to move it around the screen, and i use rigidbody.AddForce() to do so. This works absolutely fine.

However, there is a problem. To rotate it towards where i click, i do the following:

When i click:

 _targetLocation = targetLocation;
 _originRotation = transform.rotation;
 _remainingTurn = 0.0f;
 _moving = true; 

And then each update:

 if( _remainingTurn < 1.0f )
 {
 _remainingTurn += Time.deltaTime * turnRate;
 _targetRotation = Quaternion.LookRotation(_targetLocation - transform.position, Vector3.up);
 transform.rotation = Quaternion.Slerp(_originRotation, _targetRotation, _remainingTurn );
 }
 if( _moving && rigidbody.velocity.magnitude < Mathf.Min(maxSpeed, distanceToTarget * 2) && distanceToTarget > movementThresholdDistance )
 {
 rigidbody.AddForce( (_targetLocation - transform.position) / distanceToTarget * acceleration * Time.deltaTime);
 }

This makes my object rotate towards where i clicked quite nicely, but for some reason the entire object moves very choppily as long as it's rotating. I tried changing the rotation line to just set the rotation to the target rotation, but even then, without the Slerp, it moves very choppily as long as _remainingTurn is lower than 1.

Any idea what causes this?

Comment
Add comment · Show 2
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 tingham · Feb 22, 2012 at 02:53 AM 0
Share

Are you using LateUpdate ?

avatar image Pwntheon · Feb 22, 2012 at 08:30 AM 0
Share

I am using LateUpdate to make the camera follow, but not for moving or rotating the object, no.

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by Pwntheon · Feb 22, 2012 at 03:28 PM

I fixed the problem. It's solved by moving everything to FixedUpdate.

Comment
Add comment · 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
0

Answer by senad · Feb 22, 2012 at 09:48 AM

I think this might be because you are combining physics and setting the transform directly.

Maybe you should try using Rigidbody.AddTorque to rotate your object via physics instead of setting transform.rotation.

Comment
Add comment · Show 4 · 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 Pwntheon · Feb 22, 2012 at 10:52 AM 0
Share

I was thinking this as well, but i have no idea how to use AddTorque to make the dragon point where i want, if you catch my drift.

avatar image tingham · Feb 22, 2012 at 01:52 PM 0
Share

Transform.LookAt ?

avatar image Pwntheon · Feb 22, 2012 at 02:14 PM 0
Share

But that doesn't use rigidbody at all...

avatar image senad · Feb 22, 2012 at 04:32 PM 0
Share

Hey, great I see it works for you now. Although this is probably useless info now, I just want to complete the answer:

I have not used the physics system myself, but in the doku it says you specify a rotation axis and the rigidbody will rotate around it: http://unity3d.com/support/documentation/ScriptReference/Rigidbody.AddTorque.html

So if you think about your current direction and your desired direction as lying inside a plane, the rotation axis should the normal of that plane. (perpendicular to it)

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

look at movedirection 1 Answer

Apply torque to align rigidbody to a specific angle in 3D 2 Answers

Player character X rotation going haywire on game start 1 Answer

Angular restrictions in a planetary setting. 0 Answers

How to get rigidbody local z axis rotation in Euler angles? 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