• 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 Akkronym · Oct 08, 2015 at 01:38 AM · randomlerpboundsweightaverage

Calculating a value based on a weighted element within bounds?

I'm trying to write a script that will allow a game object to move in a general direction within specified bounds rather than in a specific direction. Based on what I've seen with the function LerpAngle, the angle portion won't be particularly difficult I think. It works by using a minAngle and maxAngle and interpolating between them based on a value "t" that must be between 0 and 1 inclusively. If t is 0.5, it will return the exact midpoint of the two angles; if it is 0, LerpAngle returns minAngle, and if it is 1, LerpAngle returns maxAngle.

I'll have the ideal vector (calculated elsewhere and already working) which will be identical to the midpoint, and I'll be able to treat minAngle and maxAngle as a +/- threshold from this ideal midpoint.

What I'm trying to do is programatically calculate a "t" value based on an "amplitude" variable.

When the amplitude is 0, t is calculated completely randomly. IE values should be effectively indistinguishable from the performance of t = Random.Range(0f,1f);

When the amplitude is 1, t = 0.5 no matter what.

When it is any value in between 0 and 1, I'd like it to sort of be a gradient that plots like a progressively more narrow bell curve from 0 to 1.

Rough sketch of expected performance - alt text

I'm not really sure how to implement this, but it seems like something that might already have a library function somewhere - if not necessarily unity. Can anyone either point me in a helpful direction for writing it myself, or towards an existing function that does something similar?

unnamed.png (44.4 kB)
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 Akkronym · Oct 08, 2015 at 03:58 AM

With the help of a friend I was able to figure out that the concept I'm referring to here is Normal Distribution and Random Gaussian Variables.

I don't have a working implementation yet, but based on what I've found so far a "Box-Muller Transformation" keeps coming up and seems like an effective direction to go in.

Hopefully this will help point anyone else with this issue in the right direction as well.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How can I detect non-rectangular bounds? 0 Answers

How to 'Lerp' random local vectors? (Solved!) 3 Answers

Vector3 Lerp mis-match 0 Answers

Calculate weighted mean based on direction 0 Answers

How do I smoothly shift between Layer Weights 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges