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 sinokreal · Jan 15, 2012 at 04:23 PM · triggertimerscriptingbasicsplane

How to initiated floors to fall like dominos once the game starts

first off I am really new to using Unity3d and very new to the scripting aspect. I Basically just started a week ago. But I have an idea and would like to try and test it out. I do have this script that i got to initiate the two Planes i made to fall as soon as the game starts.

// Apply a downward force to the rigid body every frame

function FixedUpdate () {

 rigidbody.AddForce (Vector3.down);

}

I know I need a trigger with a time frame, but i don't know how to code it. I wanted to add a timer to lets say Plane A to trigger an start to fall in the first second then Plane B to trigger another second after it, then the next Plane etc etc. So basically making the floors fall in segments withing a certain time frame.

As of right now i start the game and both planes A & B start to fall at the same time. I know i need functions for this but i don't know where to start scripting it. Anyone have any ideas or places they can guide me to accomplish this task?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by seealsoidiot · Jan 23, 2012 at 01:49 PM

Would just adding a rigidbody component to the planes not give you your desired effect?

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

Answer by Bicko · Jan 23, 2012 at 11:18 PM

I thought I'd have a look at what other questions you've got on your account, so here's my suggestion for this one.

What you want to do is loop repeatedly through all of the game objects, making a domino fall each time the loop happens, but you also want the loop to work on a delay between each domino.

First, you'll need to setup the dominoes. Give them a collider (Box Collider, probably) and as seealsoidiot said also add a Rigidbody component. You can find both of these in Component > Physics.

Now running the loop can be done in a couple of ways, but I'm going to keep things simple and suggest that you just make an empty GameObject and call it "Domino Parent", put all your dominoes inside this object.

What I've now done is made this script for you, I'd suggest you rework it in some manner, but it will just work if you make a new script, paste this inside, and put it on any object in your scene:

 //The domino parent variable that contains all the other dominoes
 private var dominoParent : Transform;
 
 function Start()
 {
     //Set the domino parent variable on Start
     dominoParent = GameObject.Find("Domino Parent").GetComponent(Transform);
     
     //Go through each child of the object that this script is attached to,
     //and set their rigidbody Kinematic component to true.
     for (var child : Transform in dominoParent)
     {
         if(child.GetComponent(Rigidbody))
             child.rigidbody.isKinematic = true;
     }
     
     //Start dropping dominoes
     DropDominoes();
 }
 
 function DropDominoes()
 {
     //Go through each child of the object that this script is attached to,
     //and set their rigidbody Kinematic component to false. Also add a small
     //force to the child to wake it up.
     for (var child : Transform in dominoParent)
     {
         if(child.GetComponent(Rigidbody))
         {
             child.rigidbody.isKinematic = false;
             child.rigidbody.AddForce(Vector3.down);
         }
         
         //Add a 1 second delay between each domino falling.
         yield WaitForSeconds(1.0);
     }
 }

Suggested reading: Accessing Other Game Objects, specifically the parts related to accessing children (note: all work involving parent/child game object relationships involves some dodgy wording!). Also read up on Physics Components, specifically Kinematic Rigidbodies.

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

6 People are following this question.

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

Related Questions

Making a countdown out of 3D planes. 1 Answer

How to repeat damage 1 Answer

close game in delay after pressing button 1 Answer

Enable/Disable script with timer 1 Answer

Need help with game points and trigger 2 Answers


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