• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Nov 20, 2014 at 01:40 AM by meat5000 for the following reason:

The question is answered

avatar image
0
Question by sticoRobotto · Nov 18, 2014 at 08:07 PM · physicsrigidbodyterraincharacter controllerthird person controller

How to keep rigidbody from falling through terrain?

I instantiate a prefab object into the world, and after like 10 times the objects keeps falling through the ground. Both the ground and the object have rigidbodies on them to make sure that they see eachother. For some reason the object that I am creating stops colliding with the terrain after a certain number of times. The only thing working on the falling object is gravity via rigidbody component. I do have a character with character controller and third person controller in the scene as I am performing instatiation. Any help will do.

Comment
Add comment · Show 17
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Landern · Nov 18, 2014 at 08:07 PM 0
Share

How fast is the object falling through going?

avatar image Elit3d · Nov 18, 2014 at 08:09 PM 0
Share

can we see some pictures or any code that you wrote so we can assist easier?

avatar image MrSoad · Nov 18, 2014 at 08:27 PM 0
Share

How thick (in terms of it's height, y axis) is the ground. If it is very thin then objects can easily push through it enough to fall through completely.

avatar image sticoRobotto · Nov 18, 2014 at 09:02 PM 0
Share

The speed of the object seems to be fairly slow, it seems to be affected only by gravity that rigidbody component applies to it. However, when it starts to shoot out in random directions, a more stronger force seems to be apply to it.

avatar image sticoRobotto · Nov 18, 2014 at 09:02 PM 0
Share

The ground is generated via the unity terrain creator, so I guess that would make the ground paper thin.

avatar image sticoRobotto · Nov 18, 2014 at 09:04 PM 0
Share

before I put any code let me explain further. I am using a keyboard key to instantiate object in mid air, creating a rigidbody component in the now falling object that has gravity, and it works fine. I am using the same button to Destroy(object), so that I can keep testing the physics on this object. I am using a regular sphere from unity that already comes with sphere collider and such things and the only thing I am doing is adding the rigidbody component. After like 10 or 15 times of creating and destroying this object, upon creation again, the object seems to shoot out into a random direction. I keep destroying and re creating the object and after doing this for about 5, 6 times, the object starts to behave again, and just falls down to the terrain like it does the first time.

avatar image sticoRobotto · Nov 18, 2014 at 11:59 PM 0
Share

This is the code for instance creation.

public var ballPrefab:GameObject;

private var newBall:GameObject;

private var referenceObj:GameObject;

if(Input.Get$$anonymous$$eyUp($$anonymous$$eyCode.$$anonymous$$)){

     var horseShoe:Transform = referenceObj.transform;

     if(newBall != null){
         Destroy(newBall);
     }
     if(newBall == null){

         newBall = Instantiate(ballPrefab, horseShoe.position,horseShoe.rotation);
         newBall.transform.position.y += 10;
         newBall.transform.position.z += 5;

         
         if(newBall.rigidbody == null){
             Debug.Log("new RigidBody");
             newBall.AddComponent(Rigidbody);
             newBall.rigidbody.useGravity = true;
             newBall.rigidbody.is$$anonymous$$inematic = false;
         }
     }        
 }
avatar image sticoRobotto · Nov 18, 2014 at 11:59 PM 0
Share

It seems that the problem is the scene that I am trying this on is too hectic. I tried the sphere test that I conducted on a much simpler scene and it worked 100 percent of the time. Which means, that I have too much going on, on my other scene. Anyhow, though I would mention this.

avatar image sticoRobotto · Nov 19, 2014 at 12:11 AM 0
Share

I am instantiating the object as a GameObject and then adding component rigidbody via code. Just in case this matters.

avatar image Linus · Nov 19, 2014 at 12:58 AM 0
Share

What type of collider are you using? Scene image would be handy

avatar image meat5000 ♦ · Nov 19, 2014 at 01:38 AM 0
Share

Dont use tiny colliders. You have colliders, right? $$anonymous$$aybe terrain collider on the ground?

You could increase iteration count in the Physics $$anonymous$$anager. On the Falling object rigidbody you could try changing the Collision Detection to Continuous.

Don't use silly numbers for $$anonymous$$ass. Shyt gets interesting...

avatar image sticoRobotto · Nov 19, 2014 at 02:53 AM 0
Share

I was using regular sphere collider on the sphere. I was using 5 for mass but then switched to 1. Still same problem. I did try to change collider to continuous and continuous dynamic, but it would just act up after a awhile even if the object was a brand new Intantiated gameobject. I am using terrain in unity which uses already the Terrain collider automatically.

avatar image meat5000 ♦ · Nov 19, 2014 at 03:17 AM 0
Share

$$anonymous$$arked as static?

Anyway, I don't think I ever used a Rigidbody on the terrain.

avatar image the_motionblur · Nov 19, 2014 at 06:48 PM 0
Share

Do you have a script attached to the object? If so do you use Update ins$$anonymous$$d of FixedUpdate or transform.translate ins$$anonymous$$d of forces? Do you use Unity 4.x or 5 Beta?

avatar image sticoRobotto · Nov 19, 2014 at 11:46 PM 0
Share

I am using Unity 4.5.5f1

avatar image sticoRobotto · Nov 19, 2014 at 11:47 PM 0
Share

yeah, I agree about not using rigidbody on the terrain. I will get rid of it as it should work as is. I do seem to be making the mistake of running it in Update ins$$anonymous$$d of Fixed Update. that might be able to solve the issue. I am currently working around the problem but would like to know if fixed update would solve that issue. I know fixed update is meant for rigid bodies, for example I have all the key and button presses in Update. Function gets called on button press and I create Rigidbody gameobject. How would you go about putting a rigidbody being affected by rigidbody gravity? Would you call a function on button press in FixedUpdate that would instantiate the rigidibody Object? By the way, thanks to all for your input and ideas. Really Appreciate it.

avatar image AlharbiSunds · Jul 25, 2020 at 01:15 PM 0
Share

For me, the cause was because of the Rig of my animation clip. I forget to change it to be "humanoid" for my character.

2 Replies

  • Sort: 
avatar image
3

Answer by The-Little-Guy · Nov 19, 2014 at 11:59 PM

Create the ground without a rigidbody, and place a collider on it instead. Your ground probably doesn't need to react to physics, but your object will need to react to physics so it will need a riggidbody on it AND a collider as well. You then place a Physics Material on the ground collider (which is optional) to apply either friction and/or bounciness to your player or game object.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Shockwolf · Nov 12, 2018 at 02:25 AM 0
Share

I am using an imported mesh for my terrain. There's no rigid body or Physics material on it, just a mesh collider generated by script when it is instantiated and shaped using perlin noise. I still sometimes have issues when I instantiate objects above it. They fall through it, not all of the time, but sometimes. The smaller the object the higher the chance of it falling through.

avatar image Shockwolf Shockwolf · May 13, 2020 at 03:59 AM 0
Share

It's okay, I solved my problem by changing the rigid body settings on the Objects to Extrapolate and Continuous Dynamic. Having a rigid body on my terrain is also essential for using an object placement system I am using.

avatar image
0

Answer by sticoRobotto · Nov 20, 2014 at 01:01 AM

Cool thanks. I have removed the rigidbody from the terrain. I think part of the problem was that I was placing a rigidbody along with the Character controller, and there were two forces at work. I have removed the rigidbody from the Player gameobject. It seems to be working fine now.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image The-Little-Guy · Nov 20, 2014 at 07:39 PM 3
Share

No problem! Note: You shouldn't post comments to answers as a new answer, you should post it in the comments of the answer.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

My object falls through terrain. 8 Answers

Force on Character Controller (Knockback) 4 Answers

Object Flies into Air Upon Collision, or goes through hill depending on isKinematic settings 1 Answer

How to setup character Collisions? 2 Answers

CharacterController jumps when colliding with kinematic rigidbodies 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges