Unity. Trying to fake the vessel’s internal gravity. Children of a solid body of a rotating object continue to slide

I am trying to simulate a ship / space station with internal gravity.

To achieve this, I make the player and the entire contents of the ship the children of the ship. The ship itself has colliders, but does not contain solid components of the body. The idea is that as the ship moves, so does its entire contents. Still pretty simple.

To simulate gravity on a ship, the player’s controller and all rigid bodies turned gravity off by default. Instead of the standard, each frame applies force along the negative vector of the original parent ship.

Similar works, but there is one serious problem that I must solve before this thing is solid. All rigid bodies glide very slowly along the inside of the ship.

I know that this is probably due to the updated position of the floor in combination with gravity, leading to some kind of shear force. Objects always glide against the rotation of the ship.

I tried dropping all physical properties from physical materials to drag them to mass, etc. None of them worked, and I am sure that this is due to the fundamental fact that the floor moves, even though RBs are children of the object of which the floor is a part.

Does anyone have a solution for this, is this not some kind of cell tape? I could try to do everything kinematic and only “wake up” when some external collisions or something else happen, but it can become very cumbersome. I need this to work as general as possible.

Some codes:

On the ship

void Update () { transform.Rotate(new Vector3(Time.deltaTime * 0.125f,Time.deltaTime*0.5f,0)); } void FixedUpdate() { Vector3 tempVec; foreach(Rigidbody rb in rigidBodies) { //Gravity!! tempVec = transform.up * -9.81f * rb.mass * Time.deltaTime; rb.AddForce(tempVec, ForceMode.Acceleration); } } 

I also worked on a version where the ship followed the movements of a rigid body. I could not do direct education, so I just had to configure the conversion manually for each frame in accordance with the physical proxy. This still had the same effect as above, although it is likely in the long run how I want to move the ship, as it will be more correctly attached to the mechanics of flight.

+4
source share
2 answers

If you equate this to a real-world scenario, the only thing that prevents us from sliding across the floor is friction.

Is the library of friction physics based on contacting materials applied correctly? If you do not apply a certain amount of friction (or the minimum force used to overcome it), this should prevent slipping on the floor.

Although this is pretty much a “sticky tape,” as mentioned above, it can fit neatly into the physics engine and expand it if it still doesn't have a way to enforce it.

0
source

As stated above, the problem is how the physical engine applies friction. If I'm not mistaken, other forces will act on the objects in the rotating frame (some of them are not very intuitive - watch this video: https://www.youtube.com/watch?v=bJ_seXo-Enc ). However, despite all this (plus probable rounding errors due to the motor itself and the joys of floating point mathematics), in the real world, static friction is greater than moving (kinetic) friction. I don’t think that this is often implemented in game physics engines, so we often see “shaky” almost static objects. In addition, you may encounter the problem that even if it is implemented, the physical engine can interpret two contacting rotating bodies as non-static (even if their contact surfaces are static from a local point of view, the engine can think globally) ... [ Insert a joke about the Newton – Einstein dispute].

https://i.stack.imgur.com/AMDr2.gif shows an idealized version of how friction actually looks in the real world: until you overcome static friction, nothing moves.

One way to implement this (if you can access the low-level physics engine) would be to round all the forces of motion below a certain threshold to zero - i.e. force <0.001 * is set to 0 (or, possibly, speed <0.001) is set to zero - whichever is easier).

* Some kind of threshold - you have to decide what it is.

Otherwise, perhaps you could instruct these objects to stop computing physics and “attach” them to the parent surface until you want to do something with them? (This is probably a bad decision, but most of the other ideas above are based on breaking the underlying physical code.)

0
source

Source: https://habr.com/ru/post/1500423/


All Articles