• 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 TurboHermit · Mar 05, 2012 at 07:22 PM · rotationgravityplanetangular

Gravitational Rotation

I'm fooling around with some body-to-body gravity discussed in this thread:

http://answers.unity3d.com/questions/13639/how-do-i-make-a-small-planet-with-gravitational-pu.html

And I went with this script and it works perfectly fine. http://www.unifycommunity.com/wiki/index.php?title=Gravity

Except for, the body that's affected by the gravity, doesn't rotate by force alone. I want the top of the object to rotate (target) towards the planet when it's being pulled by it. I can't seem to figure out how to do this.

Anyone any suggestions?

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

4 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Bunny83 · Mar 05, 2012 at 10:29 PM

Gravity never causes rotation. Gravity always pulls on the center of mass, so an orbiting object won't rotate due to gravity. On Earth objects rotate due to air-resistance and the relation between the center of mass and the center of drag.

But don't forget the golden rule in video games / movies:

 impression / appeal  >  logic

So it doesn't have to be realistic. It should look / feel good ;)

To rotate the object in the direction of movement, you could use LookAt or Quaternion.LookRotation.

 transform.rotation = Quaternion.LookRotation(rigidbody.velocity);

With this line the z-axis will always point in the direction of movement.

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 Alec-Slayden · Mar 05, 2012 at 10:31 PM 0
Share

I could have sworn that there was a drag effect that caused rotation in asymetrical rigidbodies but I see that is not true :(

avatar image TurboHermit · Mar 06, 2012 at 08:33 AM 0
Share

How would I change that code so that it affects the y-axis ins$$anonymous$$d?

avatar image Bunny83 · Mar 07, 2012 at 06:48 PM 0
Share

Well, in Unity most methods are optimised for Unity's coordinate system which means: x-axis is right y-axis is up and z-axis is forward. You can parent your projectile to an empty GameObject and compensate the rotation.

avatar image
1

Answer by Alec-Slayden · Mar 05, 2012 at 07:56 PM

Edit: I misinterpreted the way Unity's physical gravity worked (could have sworn I had a top-heavy effect work before using drag to simulate resistance) :(

I suppose I'd say use the SmoothLookAt script included in the assets, and change its target.

If you need something more accurate than the damper of SmoothLookAt, you may want to store the LookAt() rotation towards your gravity, and use Quaternion.Lerp, modified by the strength of the gravity.

Comment
Add comment · Show 5 · 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 TurboHermit · Mar 05, 2012 at 10:23 PM 0
Share

The gravity is physical, and I've tried the top-heavy approach I think. Could you explain more accurately how I would approach this?

avatar image Bunny83 · Mar 05, 2012 at 10:32 PM 0
Share

In a gravity field the acceleration depends only on the other mass. Take the classical example of a feather and a hammer fall at the same speed.

avatar image Alec-Slayden · Mar 05, 2012 at 10:35 PM 0
Share

yes, but since he implied rotation, I also figured he would be using a drag like air resistance. Which is why dropping a hammer or knife can easily result in the metal hitting the ground first.

avatar image Bunny83 · Mar 05, 2012 at 11:13 PM 0
Share

Unity's gravity works like real gravity ;)

The problem is the drag. In space there is no drag. If you add drag to your rigidbody, it will turn based on the center of mass. But if you use drag in space most of your objects will fall onto the planet like they had entered the planets atmosphere.

As already said most the time you don't want physically correct behaviour in games. You can change the rules as you need it ;)

avatar image Alec-Slayden · Mar 05, 2012 at 11:52 PM 0
Share

it sure does. $$anonymous$$y misinterpretation was in how unity's gravity responded to the 'drag' variable of a rigidbody. I thought it would cause rotation similar to the drag from air resistance, but it does not appear to. Thank you for helping to clarify.

avatar image
0

Answer by TurboHermit · Mar 06, 2012 at 08:47 AM

I tried to center the mass in the top, which it does... I also tried adding drag to the object I want rotated and though it resulted in some funny looking exploits, it still doesn't amount to the wanted effect. I think I might use the lookAt solution and make it trigger within a radius or something.

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 TurboHermit · Mar 06, 2012 at 08:47 AM

Thanks, what do I need to edit to make it look at the x-axis instead?

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

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

Why is Quaternion.FromToRotation() not working properly? 3 Answers

3d gravity on a planet 3 Answers

AddTorque but don't rotate around centre of mass? 0 Answers

Rotating hinge joint over 180° with angular limit 1 Answer

Rotational Gravity - Camera and Force problems 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges