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 /
avatar image
0
Question by Olya_Vashchenko · Jul 06, 2018 at 05:02 PM · rotationrigidbodysphereaxes

Rotating sphere with rigidbody attached

Hello! I have a sphere with rigidbody and sphere collider attached. I want it to move forward/backward using vertical input and to rotate along Y-axis using horizontal input. But there arises 2 problems:

1) When the sphere moves, its axes change (in local scope) and sometimes it rolls aside instead of rotating along the y-axis.

Maybe I have to first set sphere's rotation to zero and only then rotate it? I've tried transform.Rotate and rigidbody.rotation, both methods worked, but they were unnatural and way too fast. While I want my sphere to be affected by physics forces.

If there's a way to smoothly rotate an object form the any current rotation to "0, horizontal input, 0", please tell me about it :)

2) After the rotation is done I want my sphere to move forward/backward according to its current rotation (local vectors' direction). Is the right way to do that is using Rigidbody.AddRelativeForce() ?

I'm new to Unity, therefore any help will be appreciated!

P.S.: sorry for possible grammar mistakes.

Comment
Add comment · Show 6
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 JVene · Jul 07, 2018 at 06:18 AM 1
Share

You have basically two options when moving objects. You either use forces and allow the object to do what those forces cause it to do (which means you won't have such strict control over the object as to keep it's rotation aligned), or you ignore forces and move the object by altering it's position and rotation - but this means you're ignoring all physics (basically).

Combining the two concepts is going to lead to nightmare level headaches, because the physics engine is not designed to allow for it (even though you can perform the act in code, you'll cause very strange results, sometimes puzzling, sometimes hilarious).

One advantage to using forces is that you're going to get fairly smooth motion (all factors being in control toward that result, which is to say NOT punching a sphere with the equivalent force of a jet engine).

When you move something by script through an object's transform, you take responsibility for time. That is, you're going to have to consider each and every frame, and the small, sequential bits of motion required for each frame (or fixed timestep) in order to accomplish smooth motion.

Say, for example, you wanted a ball to spin on the Y axis (we're talking clockwise looking down upon the ball from above, right?), but only from script, not by adding a torque. Let's say you wanted it to spin at 60 RP$$anonymous$$, which is 1 revolution per second. Let's say you decide to used the FixedUpdate firing 60 times per second. You'll need to rotate the object's localRotation in Y by 6 degrees each time step. (Note, you can do it in Update, but that's not fixed, and can vary from frame to frame, depending on what else is going on - meaning that wouldn't be 6 degrees each frame, it would vary according to time). In either case, you'll use Time.deltaTime to know how much time has elapsed since the last update (or fixed update).

avatar image Olya_Vashchenko JVene · Jul 07, 2018 at 08:47 AM 0
Share

Thanks for your answer! Very sad, that the physics engine doesn't allow for so much control over the object... I'll try to do it from script (but it will take a few days,definitely). Then I'll update my question.

avatar image hexagonius Olya_Vashchenko · Jul 07, 2018 at 09:02 AM 1
Share

There's a third solution: Every object has an angular velocity. $$anonymous$$aking use of AngleAxis $$anonymous$$athf.RadToDeg and your input will give you full control over the rotation of a physics object when applied in FixedUpdate.

Show more comments
avatar image hexagonius · Jul 07, 2018 at 06:25 AM 0
Share

check out the roll a Ball Tutorial project

avatar image Olya_Vashchenko hexagonius · Jul 07, 2018 at 08:41 AM 0
Share

Sorry, in that tutorial the ball only moves forward/backward and aside, there is no rotation.. But thanks for answer anyway:)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by tiredamage42 · Jul 07, 2018 at 06:19 PM

Use rigidbody.AddRelativeTorque(0,horizontalinput,0) for the rotation. And then rigidbody.AddRelativeForce() for the translation

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 Olya_Vashchenko · Jul 07, 2018 at 09:47 PM 0
Share

Unfortunately, the solution isn't that simple :( I used these funtions first of all. Anyway, thank you for the answer!

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

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

How to rotate a rigidbody without rotating it's axes? 0 Answers

Freeze rigidbody position without affecting rotation - please help! 1 Answer

Rigidbody.AddForce and incorrect rotation 2 Answers

Rigidbody rotation around CenterOfMass 1 Answer

Engine weight Simulation 2 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