Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 /
avatar image
0
Question by badguy0325 · Jul 06, 2013 at 04:31 AM · collisionragdollfloor

How do I make and object fall through the floor after a specific time?

When I kill the enemy NPC, I instantiate a ragdoll gameObject with this script attached. I need the ragdoll to fall through the ground after a second, then destroy itself a second later. I have made a new layer, called "Nocollide." It is layer 10, and in the matrix is set to not collide with any other layers. After it instantiates, I look in the inspector, and it does change the layer to Nocollide, but doesn't fall through the floor. When I walk into it, I collide with it. If I make the prefab's layer to Nocollide before I press play, it falls through. I don't understand why it still collides. Please help. Thank you in advance!

Here is my script:

 void Start () 
 {
     Destroy(gameObject, 2);
     StartCoroutine(FadeAway());
 }

 IEnumerator FadeAway() {
     yield return new WaitForSeconds(1f);
     gameObject.layer = 10;
 }
Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by cdrandin · Jul 06, 2013 at 04:38 AM

You could just implement your own simply little timer. Assuming this script to be in each enemy NPC. Give it a function name Destroy. which does... what you want, but you can do it simpler. Why not remove or disable the physics component on your object after 1 sec. This will still achieve what you want, but not have to deal with layers. Also, instead of destroying you can simply disable the object and re-enable it again when you need the rag doll. If the current rag doll is being used then duplicate it. The thing to note here is Destroying GameObjects or Unity's Destroy method can be costly if you are doing it pretty frequently.

Hope this helps.

Edit: Also instead of using WaitForSeconds just making your own timer. I say this because it is expensive as well.

 float timer = 0.0f;
 if( timer >= 1.0f )
 {
     // then do something
     timer = 0.0f;
 }
 timer += Time.deltaTime;
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 badguy0325 · Jul 06, 2013 at 04:55 AM 0
Share

I will give that a try in the morning and let you know how it goes. I actually never thought of doing a timer that way before. Great stuff. The script, however is attached to the ragdoll, which is a separate gameObject that is instantiated when the enemy itself has 0 health and is destroyed. I will edit my post to clarify that. Also, I am still very puzzled as to why it doesn't fall through when it clearly changes layer, and the Nocollide layer clearly doesn't collide with anything. Anyways, thanks a lot for the reply!

avatar image
0

Answer by robertbu · Jul 06, 2013 at 06:27 AM

You can use Invoke() to cause something to happen in the future. You can cause something to fall through the floor by turning off its collider. Destroy has an optional second parameter for how far in the future the object should be destoryed. Putting the three together:

 #pragma strict 
 
 function Start() {
     Invoke("FallThrough", 2.0);
 }
  
 function FallThrough() {
         collider.enabled = false;
         Destroy(gameObject, 1.0);
 }

This code causes the object to start falling through the floor two seconds after it is created and then it is destroyed one second after that.

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 badguy0325 · Jul 06, 2013 at 04:09 PM 0
Share

Thanks for the reply! I like to use C#, but I tried your JS, and I had the same problem. I have now figured it out, though. $$anonymous$$y problem was that I had to change the layer (or in your case disable the collider) of each child, since on a ragdoll, each limb has a separate collider. Again, thanks!

avatar image
0

Answer by badguy0325 · Jul 07, 2013 at 01:24 PM

I have now figured out the answer. My problem was that I had to change the layer of each child, since on a ragdoll, each limb has a separate collider.

Comment
Add comment · 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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

15 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 avatar image avatar image avatar image avatar image

Related Questions

How would I go about setting an exclusive collision, i.e. floor that only reacts to the player? 1 Answer

Why is my ragdoll reacting differently depending on the framerate? 2 Answers

Ragdoll driven game 1 Answer

Fall Damage OnCollisionEnter Script Help. 1 Answer

How can I stop a rigidbody (Ragdoll) character from colliding with the Character Controller capsule? 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