Search Unity

  1. Unity 2020.2 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Goal keeper AI for Soccer Game

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

  1. ccoutinho


    Dec 24, 2016

    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.


    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