Search Unity

Creating a "sticky" joint on two moving objects

Discussion in 'Physics' started by HeinzT0mat0, May 4, 2020.

  1. HeinzT0mat0

    HeinzT0mat0

    Joined:
    Jan 3, 2020
    Posts:
    7
    Hi there. I got a small issue "sticking" my game objects.

    I created a flat surface (circle) that should be the base of my scene. The "speciality" is that this ground isn't fixed but is itself sitting on a pillar and should be able to rotate. So far so good. Now on this surface I have another GameObject I want the player to be able to move. (velocity + rotation)

    Now my problem is that I want that game object to "stick" to the surface while still be able to move it around. So I want to be able to move the object relative to the surface but not in height. Because the surface is moving itself I cannot simply lock the Y-Axis to achieve this.

    Because this is way harder to explan than to show there is a little Video. (instead of the car bouncing it should stick to the surface at all time)
    Untitled_ May 4, 2020 10_12 PM (1).gif
    As you can see the vehicle "bounces" and I can even fly up into space at some degree which I do not want. All four wheels should always be in contact with the platform.

    I tried chracter joint as well as Hinge Joint. with no good results.

    Thanks for helping me with this
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,912
    How about a "Smoke and Mirrors" approach?
    • Instead of rotating the platform, rotate the camera the inverse direction so that it only appears as though the platform is rotating (it is actually static)
    • At the same time, change gravity so that it is going "down" according to the perspective of the camera. Physics.gravity = -transform.up * GravityConstant (9.81f?) on the camera
    This way you won't get "swinging" forces from the platform rotating.
     
    Last edited: May 5, 2020
    HeinzT0mat0 likes this.
  3. HeinzT0mat0

    HeinzT0mat0

    Joined:
    Jan 3, 2020
    Posts:
    7
    Thanks for your reply. The only problem is: I do not really rotate the platform (programmatically). It itself has a mass and simply should react to the weight (the car and other objects) on it and so reacts to the gravity of the world. (like a balancing board)
     
  4. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,510
    You may measure the motion at the point where each object is located and then apply that motion (position + rotation) to their Transform. Modifying the Transform means "teleporting" the objects without affecting the physics. Note that you may encounter some issues to resolve (synchronizing Transforms, interpolation).
     
    HeinzT0mat0 likes this.