Hello, I’m trying to create a script in C++ that handles what happens when my enemy gets hit by an object. I have many layers of subprograms, but the core part of this program relies on whether the enemy was actually hit by the object. I’m trying to have a system set up so that when my enemy is hit by a weapon he will either dodge that attack, or take damage. The ratio of dodging to getting hurt will change based on what tier your weapon is. My problem is that I can’t figure out how to write a code that can make/use probabilities. I have my “pseudocode” for my code set up like this:
-HitMiss lvls (EASY)
- If tier1item hits runner collider
chance of gothit 75% //gothit is a subprogram that deals the damage, however I might want to format the actual code as IF THEN
If tier2item hits runner collider
chance of gothit 100%
If tier3item hits runner collider
chance of gothit 100%
If tier4item hits runner collider
chance of gothit 100%
I just don’t know how to make something that handles chances and probabilities when it comes time to write the code for real.
Yes, I actually mean C++. What I have up there is a pseudocode so that I know what I need to create as well as the order of operations. Nice profile pic btw…
Thank you! Although it’s not an accurate depiction.
Sorry to for being such a busybody, but why C++? Do you intent to write a plug-in or are you using this for something other than Unity? And if it’s any help, probability are usually handled by random number generators like Range method in Patico’s code. The equivalent in C++ (actually C, but also C++) is the rand() function.
I tried using Random.Range and even rand.range and it comes back with “Member reference base type ‘int ()’ is not a structure or union”. How do I fix it?
I meant, that you can use any Random function - from C#.NET, Unity or C++ - absolutelly any function what can give you random values.
If this give you an integer value between 0 and 100 absolutelly random, then you can compare it with propability what you need.
Concrete sintax depends on the language what you use.