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

Freeze upward movement

Discussion in 'Scripting' started by slowpuke666, Feb 11, 2020.

  1. slowpuke666

    slowpuke666

    Joined:
    May 4, 2018
    Posts:
    7
    Hello!
    How in unity to freeze only upward movement?
    For example: i have a plane and 2 game object on it and when i am colliding them, object are "flying" to the top, but i just want the objects to push each other and to fall from plane. Both objects have RigidBody and BoxCollider attached.
     
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,120
    You can freeze the vertical position of a Rigidbody. There's a checkbox for that on the rigidbody. However, that means that nothing will cause it to move up/or down, ever, unless you manually move the object in code. Is that what you're looking for? You could turn off this value when the player passes a certain location, thereby allowing them to fall if they (for example) move off the edge of the platform.

    But what shape are you objects? I use capsule colliders for character movement, and I don't experience one object pushing another object up when colliding. What kind of colliders do you have?
     
    slowpuke666 likes this.
  3. slowpuke666

    slowpuke666

    Joined:
    May 4, 2018
    Posts:
    7
    I have a primitive cube and one random object, both with box colliders. Im controling the random object, and when im colliding my random obj with cube, cube start to fly, but the cube mass is 50 and random obj mass is 1
     
  4. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,120
    Well, any time you have big differences in masses (50x, in this case), the physics can be more erratic. Have you tried making the masses closer to each other? Still, unless you're moving into the other cube very quickly, I'm surprised the small object would go up, instead of forward/away.
     
    slowpuke666 likes this.
  5. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    You might try changing the physics material of the plane so objects slide easier on it. You might be getting too much resistance to until the force becomes overwhelming and sends one of the objects flying. You could also try doing what you're doing but with spheres, which would be more prone to rolling than sliding so resistance to sliding is less of a factor (you don't have to actually change the model, just temporarily replace the box collider of the cube with a sphere collider to test).
     
    slowpuke666 likes this.