Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more..
    Dismiss Notice
  3. Dismiss Notice

Resolved How do I stop gameobjects from popping up?

Discussion in 'Physics' started by philly1164, Dec 29, 2020.

  1. philly1164

    philly1164

    Joined:
    Apr 3, 2020
    Posts:
    7
    Hello!
    I have a table and some cubes on it ( all have colliders, the cubes have rigidbodies ). When I move a cube to "shuffle" all the cubes together, they pop up into the air (depending on how fast I move the initial cube). How do I lock the cubes (i.e. stop them from "popping up") to the table without losing rotation?

    Your help is greatly appreciated and sorry for being a noob.
     
  2. AlTheSlacker

    AlTheSlacker

    Joined:
    Jun 12, 2017
    Posts:
    326
    You can constrain rigidbody degrees of freedom:

    upload_2021-1-2_11-31-32.png

    Hopefully that is enough to solve your problem :)
     
  3. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    You can freeze a certain axis like @AlTheSlacker suggests or set them to kinematic.

    how are you moving the cubes though?
     
  4. philly1164

    philly1164

    Joined:
    Apr 3, 2020
    Posts:
    7
    Thanks for the help guys! I actually figured it out and forgot to update this thread. I clamped the Y-axis in a FixedUpdate
    Code (CSharp):
    1. yPos = Mathf.Clamp(transform.position.y, yMin, yMax);
    2.         rigidBody.MovePosition(new Vector3(rigidBody.position.x, yPos, rigidBody.position.z));
     
    Last edited: Jan 11, 2021