Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed Dec 30, 2017 at 07:18 AM by TURKITIME for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by TURKITIME · Dec 30, 2017 at 06:22 AM · fallingrocks

I need help making a script of falling objects

So i am making a game where there are falling rocks and you need to avoid them, my problem is i have tried various scripts but nothing has worked i need help making a script for rocks to fall randomly in different places. I use C#

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

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by sparkzbarca · Dec 30, 2017 at 07:08 AM

well first you'll need to create a prefab of a rock.

So create a sphere, attach to it a rigidbody and sphere collider.

Then you'll need to create a script you attach to it that oncollisionenter it damages the player if it's the player and destroys itself if it collides with terrain.

To make rocks fall randomly you'll want to create an empty game object called for example rock spawner.

You'll want to attach to this object a script that takes it's position via it's transform.position and instaniates the rock prefab. you have the gameobject prefab be public so you can just drag and drop the rock you made into it from the editor so something llike

 Class RockSpawner(){
 
 public gameobject RockPrefab;
 
 RandomXPos;
 RandomZPos;
 YPos = transform.position.y; //all rocks spawn from same height.
 Transform SpawnLocation;
 
 while(DoSpawnRocks)
 {
    //insert timer to only run every second or whatever
    RandomXPos = //use mathf.rand to pick a random X in the range of the maps width;
   RandomZPos = //use mathf.rand to pick a random Z in the range of the maps depth;
    SpawnLocation.set(RandomXpos, Ypos, RandomZpos);
     Gameobject.Instaniate(RockPrefab, SpawnLocation);
 }
 

You'll notice I didn't write the code to do random numbers for you, nor did I explain how to run code only ever few seconds with a timer.

This isn't mean, it's because coding can be overwhleming but at the same time you really must do some research and put in some work.

googling C# timer function or

unity random number

these things will teach you how to create random numbers or create timers and while guidance is helpful, you'll kind of need to show yourself that you can in some respects teach yourself if you really wish to program.

If you get stuck or something you can post again in here in comments or a new question but most people will not help TOO MUCH if you don't at least post your code even if it's broken. You kind of need to show you tried and don't simply want it all written for you.

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

Follow this Question

Answers Answers and Comments

72 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 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 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 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 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

Why does the object keep falling? 2 Answers

Rays drawn using Debug.DrawRay "fall" in editor view 1 Answer

Crouching and falling through floor 0 Answers

Animated physics causes model to go slowly through 1 Answer

Character still falls. 0 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