Search Unity

Ask/Need Helps Fuzzy In Unity

Discussion in 'Scripting' started by fajar9989, Sep 17, 2014.

  1. fajar9989

    fajar9989

    Joined:
    Oct 7, 2013
    Posts:
    1
    i have some trouble making scoring in game using fuzzy logic...
    i don't know where to begin to create the fuzzy system.
    can someone help me please....
    if you can give me some code how to make simple fuzzy in C# i really appreciate it...

    FYI : i want to make dynamic scoring in unity, for example when a bomb exploded, some troops near the center of explosion are get bigger damage than troops that stand far from the center of the explosion...
     
  2. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884
    So pretty much what you're trying to do is apply more damage to enemies that are closer than the others?

    I can't give you any code but what I can do is try to alleviate the idea.

    In my personal assumption I'd make it where when the bomb or whatever goes off, to shoot out two or more different kinds of Raycasts to deal with different damages the closer you are.... Such as Ray 1 = instant kill, Ray 2 = take 70 Health, Ray 3 take 35 health, ray take 5 health or something....

    I hate raycasts so I'm not even going to try to code a ray even though it's simple, I still don't fully understand how to properly use them, however that's how I would try to go about doing it first...

    Or you can try to make two or more triggers turn on at different times then destroy after period of time which I would say quite fast..

    But I'm sorry i don't know what Fuzzy Logic or a Fuzzy System is or I'd help more on that.
     
  3. zDemonhunter99

    zDemonhunter99

    Joined:
    Apr 23, 2014
    Posts:
    478
    You could compute the distance between the bomb and enemy and make the closer take more damage and the one farther less damage. It might not be the most efficient method, but it gets the job done.
     
  4. GarBenjamin

    GarBenjamin

    Joined:
    Dec 26, 2013
    Posts:
    7,441
    zDemonHunter99 has the way to do it. For your fuzzy impact system you'll have the traditional range from 0 (no damage) to 1 (max damage). Choose an explosion radius / distance of the damage effect. Say the distance is 10 (just 10 up to you to decide if this is feet, meters etc) now look at all enemies within that distance of 10. Say one is at distance 1, another at distance of 3 and a third at distance of 6. You simply calculate 1 / enemy distance. So the first enemy gets 1/1 = 100% damage. Any enemy at or less than a distance of 1 gets the full damage. The second enemy gets 1/3 = 33% damage and the furthest enemy gets 1 /6 = ~17% damage. That's the basic idea anyway. You'll need to play around with the numbers and maybe use some range modifiers to tweak the system to get the exact results you want.