Search Unity

Apply intelligence to Object

Discussion in 'Scripting' started by Vinit, Jun 3, 2011.

  1. Vinit

    Vinit

    Joined:
    May 21, 2011
    Posts:
    21
    I am currently developing a game of player vs IPAD type. So I will like to invite suggestion on how we can apply intelligence in order to update position of IPAD object according to our player object so the complexity of game can be increased.
     
  2. Jesse Anders

    Jesse Anders

    Joined:
    Apr 5, 2008
    Posts:
    2,857
    AI is typically highly context-dependent; as such, we'll probably need to know a lot more about the game in order to provide any useful feedback.

    Can you provide more details? What type of AI are you looking for?
     
  3. Vinit

    Vinit

    Joined:
    May 21, 2011
    Posts:
    21


    I am developing a game on Air Hockey. So when the user selects Player vs IPAD mode, the mallet on IPAD side should give the movement as if the actual player is playing even when the puck is in the player zone and thus when the puck enters into IPAD zone, it should strike back to the player side, thus preventing player from scoring, but not always.

    Any kind of guidance in this context will be really appreciated !
     
  4. Jesse Anders

    Jesse Anders

    Joined:
    Apr 5, 2008
    Posts:
    2,857
    Such AI could be fairly complex, and there's a variety of ways it could be done.

    Here's one approach you could try though. Start by determining the 'ideal' position and direction of motion of the AI-controlled player's mallet at any given time. Even here there are multiple ways it could be done, but here are some 'rules' that could be applied:

    - When on defense, the ideal position is the closest point to the AI player's mallet on the line segment connecting the puck and the closest point on the AI player's goal. In other words, it's the closest position to the mallet's current position that would effectively block a straight-line shot at that moment. (Since the mallet has width, there's some leeway there, and factoring in the angle of reflection would be one way to make the AI more sophisticated.)

    - Additionally, the position of the human player's mallet could be taken into consideration. For example, if the human player's mallet is positioned so as to make a bank shot, the AI mallet would move to block that shot rather than a straight-line shot.

    - When on offense, at any one moment the AI player will likely have a few shots to choose from; one or two straight-line shots (depending on the width of the goal and the position of the human player's mallet), and some number of bank shots. The shot for which the distance at the closest approach to the human player's mallet is greatest can then be chosen to maximize (more or less) the chance of scoring.

    Once you've identified the ideal configuration for the AI mallet, you can then introduce a random element to keep the AI from playing 'perfectly'. You could also introduce the elements of reaction time and maximum mallet speed to add additional complexity.

    As for how to approach the implementation, I'd suggest adding and testing one feature at a time, starting with a 'perfect' AI opponent (more or less) and building up from there.

    In terms of adding additional sophistication, it might be useful to think about how a human would play air hockey, and what kind of decisions and strategies are involved. Then, you can try to recreate these in code.
     
  5. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
    Heh, I just was about to write out a lot of untested stuff that I wasn't even for sure was going to half way work...

    Consider that the puck's position + the puck's velocity is the end of one seconds worth of travel. (mps) This is the area that you need to be in to stop the puck one second from now. You need to then get the distance from the puck to the mallet and use that in a calculation for where the mallet needs to be to stop it. Check then to see if the movement speed of the mallet allows it to intercept the puck. If so, move to that location. If not, you need to do a calculation to intercept the puck at the distance that is possible by the mallet. (so if the puck cannot be intercepted by simply moving the mallet sideways, you pull it back to intercept the puck. This is why many good players always play with their mallet in the center of the table. ;) ) Approaching it from present position to intercept position is good.

    Remember to move your mallet by velocity, not by Translation. Translation doesn't translate very well in a rigid body.