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 /
avatar image
0
Question by FutchProductionsSyndicate · Jun 07, 2011 at 02:21 AM · randomsmoothrange

Smooth Random.Range

I would like to Smooth the Random.Range function so the numbers gradually change.

Is there any way to do this using a Mathf.Lerp function?

This is for creating lightning in the Linerender component that gradually shifts from one random to another.


FPSyndicate

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

Answer by hellcats · Jun 07, 2011 at 02:53 AM

Ah, what you're looking for is the Perlin noise function. If only you'd had that notion about 15 years ago, it could have been you accepting the Academy Award for Technical Excellence! You can find a C# class implementation in the "Procedural Examples".

There are 1D, 2D and 3D versions. Basically, you use some smoothly varying input (like Mathf.Sin), and it gives you a smoothly varying random output. A key feature is that for a given input, you always get the same output.

Comment
Add comment · Show 4 · 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 FutchProductionsSyndicate · Jun 07, 2011 at 05:28 PM 0
Share

Thakns! i have the procedural examples, and was trying to replicate their lightning using the line renderer, ill try that!

avatar image FutchProductionsSyndicate · Jun 07, 2011 at 06:43 PM 0
Share

Are there any tutorials on how to implement the perlin noise? because i have the C# Class, but it won't allow me to add the script to my gameobject.

avatar image hellcats · Jun 07, 2011 at 06:56 PM 0
Share

No, you can't add Perlin as a component to your game object because it doesn't derive from $$anonymous$$onoBehavior. But that is ok, because you can just add it as an instance variable and use it in your current Update() method. That is what Start() or Awake() is for: to perform more complex initialization of your game object that doesn't happen by default. There is no reason to make Perlin a component because it is part of the implementation of your game object. It is better to hide such details behind the class abstraction.

So you want something like:

private var Perlin:perlin = new Perlin();

avatar image Joshua · Jun 07, 2011 at 07:19 PM 0
Share

Actually.. http://forum.unity3d.com/threads/52308-Hidden-stuff-in-Unity-(reflection-is-great)

avatar image
1

Answer by aldonaletto · Jun 07, 2011 at 02:31 PM

This is a simple solution, hope it may help you. Swings the number smooth between 0 and 1 at a rate defined by slope, and changes swing direction at random intervals defined by interval or at the limits 0 and 1. Adjust slope and interval to get the desired results.

 var slope:float = 0.5;
 var interval:float = 1;
 private var smooth:float = 0.5;
 private var tNext:float = 0;
 private var dir:float = 1;
 
 function Update(){
 
     if (Time.time>tNext){
         tNext += interval*(0.5+Random.value);
         dir = -dir;
     }
     smooth += dir*slope*Time.deltaTime;
     if (smooth>1 || smooth<0) dir = -dir;
     smooth = Mathf.Clamp(smooth,0,1);
     // Example: using smooth to vary amb light
     RenderSettings.ambientLight = Color.white*smooth;
 }
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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Store multiple random integers in an array? 4 Answers

[Beginner] Using Random.Range in initial game object position 1 Answer

Prevent Random.Range From Repeating Same Value 1 Answer

How can i add random range to an instantiated objects rotation? 1 Answer

How to generate a Random Float Variable 4 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