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. Dismiss Notice

Objects falling through floor

Discussion in 'Scripting' started by twigg1012, May 3, 2017.

  1. twigg1012

    twigg1012

    Joined:
    Nov 5, 2016
    Posts:
    4
    I'm working on a vr game where you can pickup an object and place it down, I want the object to stay put and not move when bumped into by other objects. I set it up so that when it collides with the floor it becomes kinematic and doesn't move, that works if I drop the object and let gravity take it, but if I place the object with my hand, if it intersects or goes through the floor at all, it falls into oblivion when I let go. I have the floor set with a box collider and rigidbody and a separate game object is the trigger and all the objects being picked up also have rigidbodies and box colliders. What am I doing wrong?
     
  2. paulbuck86

    paulbuck86

    Joined:
    Apr 17, 2017
    Posts:
    15
    On rigidbodies, turn Kinematic on.
     
  3. twigg1012

    twigg1012

    Joined:
    Nov 5, 2016
    Posts:
    4
    Wow, it really is that easy, Thanks!
     
    BrandyStarbrite and paulbuck86 like this.
  4. Tonymotion

    Tonymotion

    Joined:
    Dec 5, 2018
    Posts:
    12
    Years later, still just the right answer that I would not have guessed.
    Thank you, Paulbuck86!

    Update: After I activated Kinematic on my object's RigidBody, although my moving object no longer fell through the surface, it also no longer responded to the AddForce I applied to its RigidBody. I had to add a Capsule Collider to my object, & then it worked.

    I can't figure out, though, why the Box Collider on the object didn't prevent it from falling through the surface, but the Capsule Collider did. And why did selecting Kinematic on the object's RigidBody stop AddForce from working? Does anyone know?
     
    Last edited: Jul 24, 2020
    russiakun and vrBuilder like this.
  5. mahnoorcodes

    mahnoorcodes

    Joined:
    Jan 9, 2021
    Posts:
    2
    Im having a similar issue. I wonder why this happens :/
     
    vrBuilder likes this.
  6. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,842
    It's because the whole point of Kinematic is to place your object no longer under the control of the physics engine. This is only the right solution if you want your objects to no longer be affected by physics.
     
  7. DewiMorgan

    DewiMorgan

    Joined:
    May 20, 2018
    Posts:
    6
    It's probable that the box colllider was marked as a trigger.

    https://docs.unity3d.com/Manual/class-BoxCollider.html says:
    "Is Trigger: If enabled, this Collider is used for triggering events, and is ignored by the physics engine"

    These colliders do detect collision (ie intersection with other physics objects), but do not prevent it.
    If you want to do both, you may be able to do it with a single box collider, which is not marked as a trigger; or you may be best creating two; the one to prevent collision being slightly smaller than the one to detect it.
     
  8. thientv84

    thientv84

    Joined:
    Mar 2, 2013
    Posts:
    4
    hey, change collision detection from the rigid object to continuous fixed my problem
     
  9. wechat_os_Qy01eDJfSV7CWSHuAPwDqgMCA

    wechat_os_Qy01eDJfSV7CWSHuAPwDqgMCA

    Joined:
    Aug 4, 2022
    Posts:
    8
    It's 2022, and I'll end this problem once and for all:
    How to prevent a rigidbody object from falling through the floor:
    1. Settings for the floor: The floor must have a collider component, and the collider component must have isTrigger property UNselected.
    2. Settings for the object: The object must have a collider component, and the collider component must have isTrigger property UNselected. The Collision Detection property of the rigidbody component can’t be Discrete (it must be continuous __).
     
    davidmilam and TrypiCali like this.
  10. megamanx8123

    megamanx8123

    Joined:
    Apr 5, 2023
    Posts:
    1
    Nah, at the 2 u said, the isTrigger is needed for example : collecting it, if u do that so how can we- player collect object on ground ?
     
  11. SeanBotha

    SeanBotha

    Joined:
    Aug 4, 2019
    Posts:
    10
    A easy fix is adding 2 colliders on the object. Set one as trigger and other not. I am sure there is a better way but this is fast and easy. Object has gravity/physics and still is a trigger