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

· Add your reply
  • Sort: 
avatar image
0

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
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 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 ins$$anonymous$$d 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.

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

Implementing wander mode 0 Answers

this script in Javascript?? 0 Answers

Unity mathematics phrasing. 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