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
1
Question by Travis 17 · Jan 02, 2011 at 11:23 PM · javascriptairandom

how do i implement probability in java script

i was wonder how i would use probability in script for unity preferably java. some examples like: the probability the Ai soldir in the game will see your player when he's wearing camo. like how would i use it so there is a 60 percent chance the Ai will spot you when a bool prop is true or say a card game like poker and getting random cards. any type of explination will be appreciated preferably a example for each typed in script

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
5

Answer by BinaryCaveman · Jan 02, 2011 at 11:46 PM

You would want to generate a random number, using Random.Range(min, max) - (min is inclusive, max is exclusive). Read more here.

A simple example for the soldier situation could be:

var soldierCanSeeYou : bool = true;

// if prop is true and a random number between 0 and 100 is less than 60 (60% chance) if (soldierCanSeeYou && Random.Range(0, 100) <= 60) { // Soldier has spotted you (run!!!) }

another for the cards example:

 function getRandomCard() {
      var cards = new Array( '1', '2', '3', '4', '5', '6', '7', '8', '9', 'J', 'Q', 'K', 'A' ); // an array containing all the possible types of cards to get
      return cards[Random.range(0, cards.length)]; // use the Random.Range() function again to get a random card in the array and return it
 }
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 Jesus_Freak · Jan 03, 2011 at 12:15 AM 0
Share

good job! but it's in c# (even though its extremely easy to convert to unityscript.) just saying to anyone who doesnt know scripting, this is a c# example.

avatar image Jessy · Jan 03, 2011 at 12:37 AM 3
Share

No it's not. Why did you say that?

avatar image BinaryCaveman · Jan 03, 2011 at 01:09 AM 0
Share

As far as I know, this is JavaScript, UnityScript, whatever you want to call it.

avatar image d3coy · Jan 03, 2011 at 02:31 AM 0
Share

Yea... this is definitely javascript/unityscript.

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

No one has followed this question yet.

Related Questions

random target selection 2 Answers

AI for enemy characters 1 Answer

Top Down Shooter Enemy AI using raycasting 1 Answer

Need help with javascript AI 1 Answer

Enemy AI Problem: Dancing? 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