Search Unity

Goal keeper AI for Soccer Game

Discussion in 'General Discussion' started by ccoutinho, Jun 1, 2017.

  1. ccoutinho

    ccoutinho

    Joined:
    Dec 24, 2016
    Posts:
    20
    Hi

    I am trying to build a Soccer game and am having difficulty in getting the goalkeeper AI to work.

    I have Save Animations which cause the goalkeeper to dive left or right based on the direction in which the ball is moving which works well.

    However if the ball is shot into either upper or lower sides of the goal, I want the goal keepers hand Left or Right (depending on the side he is diving) to reach out and stop the ball.

    I have the below listed IK code setup, where BallIntersection.share.ballIntersect are the X,Y,Z coordinates to where the keepers hand should reach to stop the ball, however his hand can never reach these coordinates.
    The variable _weight has been set to a value of 1.

    Can anyone please help me with this, or is there an easier way to develop a goal keeper AI with such functionality.

    I have attached my Goal Keeper Script as a Text file to this post.

    Thanks.

    private void OnAnimatorIK()
    {

    if (!AnimatiorIsPlaying ("save")) {

    //Debug.Log ("Idle animiation will play");
    _animator.SetIKPositionWeight (AvatarIKGoal.LeftHand, 0);
    _animator.SetIKPositionWeight (AvatarIKGoal.RightHand, 0);


    } else {

    // we set the goalie position and position weight to reach for the ball

    _animator.SetIKPosition (AvatarIKGoal.LeftHand,BallIntersection.share.ballIntersect );
    _animator.SetIKPosition (AvatarIKGoal.RightHand,BallIntersection.share.ballIntersect );

    _animator.SetIKPositionWeight (AvatarIKGoal.LeftHand, _weight);
    _animator.SetIKPositionWeight (AvatarIKGoal.RightHand, _weight);


    }

    }
     

    Attached Files:

    • GK.txt
      File size:
      9.2 KB
      Views:
      1,130