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 glenrhodes · Apr 03, 2014 at 02:42 PM · physicsmathsphereball

Need help with the physics and angles of gerbils in a plastic ball..

Ok, so I know that's an odd question, but the problem is simple.

I have an inverted sphere, with an object inside it, resting at the very bottom. So if the sphere is at 0,0,0 and the radius is 100, then the object is resting at 0,-100,0. Think of this "object" as a Gerbil, or a Hamster.

Now, here's where I'm having trouble with the math.

If the Gerbil moves along the "ground" (along the xz plane), I want the sphere to move with him. Now that would be as easy as setting the position of the sphere, relative to the Gerbil. But I also want the sphere to have rotated by the appropriate amount in 3d space.

So rather than try to move the sphere, I want to rotate it in such a way that the gerbil is always on the bottom.

I'm having trouble figuring out the math to calculate the delta angle on the edge of the sphere, based on the delta position that the Gerbil has moved.

Any ideas?

EDIT: To clarify - I need the sphere to be anchored at 0,0,0 - and the hamster's movement just rotates the sphere. Hamster controls the sphere, the sphere does not control the hamster.

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 robertbu · Apr 03, 2014 at 03:17 PM 0
Share

Are you trying to do this with Unity physics (Rigidbody), or are you doing a direct manipulation of the transform? The angle change is easy to figure out assu$$anonymous$$g perfect rotation. The circumference of the circle with be 2*PI*R. Given a specific amount of ground travel the angle will be 360.0 * movement / circumference. If this is 3D, you can use the direction of the cross product of the gerbil direction with Vector3.up to get the axis of rotation.

avatar image glenrhodes · Apr 03, 2014 at 03:41 PM 0
Share

Basically, I have a player controller inside a giant sphere. As the player walks in any direction, I want the sphere to rotate under him so his feet are always on the "lowest" point of the sphere.

So the player could look "UP" and see something cool on the far opposite side of the sphere that would appear upside down to him, and begin heading in that direction, and eventually it would meet him. It's a person walking on the "inside" of the world. Journey to the centre of the earth, kind of thing.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by glenrhodes · Apr 06, 2014 at 03:21 PM

So I solved this by letting Unity do the work. Basically, I created a separate "Simulator sphere" with a rigidbody, and placed it elsewhere in the world, on a massively large plane.

Then, I place the camera at the bottom of the large "world" sphere. Then, I look at the Input.GetAxis to see which way the player is moving. I then AddForce to the "simulator sphere", and it rolls according to the forces.

I then set the rotation of the world sphere to be equal to the rotation of the "Simulator sphere". So it effectively feels like you're controlling the ball that you're inside of, and works perfectly as expected, even though the world sphere never moves, it just rotates.

You feel like you're walking around this "hollow earth" world, but really, it's just rotating to match what a sphere elsewhere in space is doing in response to your key presses. Works quite nicely.

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 perchik · Apr 03, 2014 at 03:09 PM

If I was doing this, here's how I'd approach it:

alt text

In 2d, as your gerbil moves forward, he's running on the edge of a circle, which is an arc of the circle. Given the arc and the radius, you can find the angle pretty easily.

In 3D, there is always some 2D circle in the same plane as the gerbil (if you think about the gerbil as a flat plane; but the same thing should work if you just consider the gerbil's midline). So then it's a matter of finding two things: first, the angle the circle traveled and second, the axis that that circle is centered on relative to the sphere.

The first part is easy, uses the same math from above. The second part is more interesting/complex. It seems to me that there's some rotation around the vertical axis that will describe the circle, since the gerbil is always on the ground. So I'd figure out what that is, (probably by getting angle between gerbil.right and ball.right or something like that), then do the math to figure out how far the ball needs to move in that direction. Rotate the ball by the first angle, around the vertical axis, then rotate by the second angle around the right axis.

Maybe. Who knows.


gerbils.png (26.5 kB)
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 glenrhodes · Apr 03, 2014 at 11:35 PM 0
Share

Thank you for this. I love the diagrams especially...

I'm trying to figure out the last part... "probably by getting angle between gerbil.right and ball.right"... I tried rotating by "player.transform.forward * velocity" just to see what would happen.. and it basically worked.... but at some angles, really weird things happened.. the sphere around you started rotating very oddly.. sideways, fast, slow, wobbly.. this is breaking my brain.

avatar image robertbu · Apr 04, 2014 at 01:46 AM 0
Share

You want to do an Quaternion.AngleAxis() rotation for rotating the ball. You can find the axis by:

 var axis = Vector3.Cross(gerbil.forward, Vector3.up);
avatar image glenrhodes · Apr 04, 2014 at 06:24 PM 0
Share

Hmm, that sort of worked -- but it still seems that as you get further away from the "zero" point of rotation, the weirder the rotation gets. At a certain point in the sphere, the rotation ends up going perpendicular to your .forward.. and then as you work your way back around to the bottom of the sphere, it comes back to normal again..

avatar image perchik · Apr 04, 2014 at 06:42 PM 0
Share

Yeah, so I'd probably do it as two separate rotations,

first I'd do something like

 float dir =Vector3.Angle(player.forward, ball.transform.forward);
 ball.rotate(ball.transform.up, dir);



(so now the balll faces the same way as the player)

then

 float distPerStep = //whatever this number is...how far each step moves the player forward
 float ballRadius =//radius
 
 float theta = disPerStep/ ballRadius
 
 ball.rotate(ball.transform.right, theta); //this should spin the ball so that the player is down again.

I think this will work, but there's probably a way to do it that only has to do one Rotate call.

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

21 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

Related Questions

Simulating the graphics of a rolling 3D ball in a 2D game 2 Answers

Ball jump on collision problem 1 Answer

Strange sphere/physics rolling behaviour when scaled 1 Answer

Ball Doesn't Roll Down Hill - Physics Problem 3 Answers

How do I calculate the arc of a throw, given two positions and an angle of attack? 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