• 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
Question by vipvex · Mar 26, 2012 at 05:48 AM · javascriptunderstand

Need help to understand code!

I found this code and when i run it, the code creates particles in a 1024 by 1024 by 128 radius (Like minecraft but particles). I tried anylizing this it, but when i got about half way through i got stuck. I tried looking it up but didn;t fined anything that has a good explination of how it works. Could someone please explain what the code means that i'm confused on. If you could brake it down into what each part does would be awesome. thanks. Code: using UnityEngine; public class NoiseTest : MonoBehaviour{ private ParticleEmitter m_ParticleEmitter; // Use this for initialization private void Start() { m_ParticleEmitter = gameObject.GetComponent<ParticleEmitter>(); } private bool m_FirstTime = true; // Update is called once per frame private void Update() { Debug.Log(m_ParticleEmitter.particleCount); //number of particles in the current particel int count = 0; Particle[] particles = m_ParticleEmitter.particles; for (int x = 0; x < 1024; x++) { for (int z = 0; z < 1024; z++) { for (int y = 0; y < 128; y++) { float groundHeight = PerlinSimplexNoise.noise(x*0.001f, z*0.001f, y*0.001f)*64.0f; groundHeight += PerlinSimplexNoise.noise(x*0.01f, z*0.01f, y*0.01f)*32.0f; groundHeight += PerlinSimplexNoise.noise(x*0.1f, z*0.1f, y*0.1f)*4.0f; //groundHeight = Mathf.Clamp(groundHeight, 0, 127); particles[count].position = new Vector3(x + y, groundHeight, z); if (count < particles.Length -1) { count++; } else { UpdateDisplay(particles); return; } } } } } private void UpdateDisplay(Particle[] particles) { m_ParticleEmitter.particles = particles; } }

Comment

People who like this

0 Show 0
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

· Add your reply
  • Sort: 
avatar image

Answer by oxium · Mar 27, 2012 at 08:53 AM

this code is simply updating some particles position (y) until the particles array is full or it has updated all of them

then it returns from the Update function

it's using a perlin noise to move each particle height position..

not that hard to read..

anyway hope that helps..

Comment

People who like this

0 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 vipvex · Mar 27, 2012 at 07:01 PM 0
Share

Why does it write (x*0.1f, z*0.1f, y*0.1f)*4.0f instead of (x*0.1, z*0.1, y*0.1)*4.0 without the "f"? Is there a reason it should use f? will it not work without it?

avatar image by0log1c · Mar 27, 2012 at 07:08 PM 0
Share

the f after a number is a quick way to indicate a float. It is not required if the code already knows the number is a float or if you're using Javascript but it is a good practise to use it.

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.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Rotating GameObject with transform.Rotate issue! 1 Answer

Set timer to a specific time. 1 Answer

Unity mathematics phrasing. 1 Answer

What is the problem with this code? 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