playMaker

Author Topic: Angular Velocity or Torque with offset.  (Read 377 times)

Doh

  • Full Member
  • ***
  • Posts: 124
    • View Profile
Angular Velocity or Torque with offset.
« on: March 11, 2019, 09:42:51 AM »
Hey, I was wondering if anyone knows how I might go about creating an orbit-like effect. I'm not looking to create a new center of gravity at all, just something like the "Rotate Around" action but using rigidbody physics. I've included an image to illustrate what I mean.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14684
  • Official Playmaker Support
    • View Profile
Re: Angular Velocity or Torque with offset.
« Reply #1 on: March 11, 2019, 11:01:08 PM »
Hi,

 you could use a joint, that would do, but if you want the orbiting planet to be a free body when it comes to collisions, then you'll need something closer to reality, meaning that you have to simulate the gravity with a force ( a force pointing at the orbit center), and also also maintain a velocity for the object to revolve. however doing that is tricky as you need to understand physics math properly, else it overshoots or undershoots.

a last option would be to switch off the rigidbody while rotating around it's orbit and as soon as it collides, turn it into a free rigidbody, so rotating around the orbit is easy, it's simply math.


you can also look on the asset store for such systems,

https://assetstore.unity.com/search?q=gravity&q=sphere&k=gravity%20sphere


 Bye,

 Jean

Doh

  • Full Member
  • ***
  • Posts: 124
    • View Profile
Re: Angular Velocity or Torque with offset.
« Reply #2 on: March 12, 2019, 05:44:26 AM »
Thanks for the explanation Jean, I think my wording and certainly the image have been a bit confusing though. The situation is not quite like a planetary body orbiting a central mass.

I'm revisiting an old setup I had for a conveyor system, due to odd behavior as the rigidbody objects transition from one piece of conveyor to the next, specifically straight pieces to corner pieces and visa-versa. The straight sections use a set velocity to move all of the rigidbodies along the surface of the belt, then corners are very hacky, they parent each rigidbody to a rotating empty game object. The main issue is the velocity applied on the straight sections is not taken into consideration as they are transitioning to the corner section, there is a momentary unwanted acceleration as the force stacks on top of the rotating empty.

So it's a situation where the orbit is only ever around the Y axis. The rigidbodies must be fully active to be able to be knocked around by other forces, colliders and each other.

I'll see what I can do with joints, but I have a feeling that may get a bit messy in some situations.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14684
  • Official Playmaker Support
    • View Profile
Re: Angular Velocity or Torque with offset.
« Reply #3 on: March 17, 2019, 11:37:03 PM »

Doh

  • Full Member
  • ***
  • Posts: 124
    • View Profile
Re: Angular Velocity or Torque with offset.
« Reply #4 on: March 18, 2019, 08:45:06 AM »
I picked up one that cost around $5 a while ago, it works very nicely, I will likely use it in the end but it'd be a bit annoying that I had to use someone else's solution. Not to mention having a cluttered project and things are never quite fit for my purpose, I find.

I managed to get a more dynamic solution built a while back, that involved a spline to create the mesh and also provide the direction to apply the force, however I couldn't (with my awful understanding of math) prevent the rigidbodies from drifting off to one side eventually. It was a shame as I could do figure of eights with an under/overpass section or any shape I could throw together.

Thanks again though! Your input has stopped me obsessing over this.