Realistic Soccer Ball Dribbling?

Hey Folks!
iam currently working on a soccer game and the dribbling looks like this at the moment:

and this script on the ball:

void OnTriggerEnter(Collider collision)
      {
         
          ControllingFeet = collision.transform;
       }
 
  void FixedUpdate()
      {
         
 
          bool isControlled = ControllingFeet != null;
 
          if (isControlled)
          {
         Vector3 targetPos = ControllingFeet.transform.position;
             GetComponent<Rigidbody>().MovePosition(targetPos);
          }
      }

which actually just mean that, when the ball enters the trigger (which is in front of the character) it transfers the position of the collider (ControllingFeet) to the Ball.

i tried to copy the transform position of the Feet to the collider which is controlling then the ball like this:

using UnityEngine;
  using System.Collections;
 
  public class Copyposition : MonoBehaviour
  {
      public Transform itsTarget;
 
      void Update ()
      {
          transform.position = new Vector3(itsTarget.position.x, 0 ,itsTarget.position.z);
      }
  }

but that looks stupid - and not natural at all as you can see in the second half of the gif.

after that i tried to delay the movement of the ControllingFeet like this:

 transform.position = new Vector3(itsTarget.position.x+0.8f, 0 ,itsTarget.position.z);

and it comes a tiny bit closer to what i want to achieve. but only works on the X axis ( move to the right) and looks like this:

i am kinda stuck how to apply the “delay” for all directions. how could i do this?

or is somebody here having another idea how i can make the ball movement more natural?

1 Like

What if you set the rotation of the ball to that of the feet? That way when you turn, the ball constantly turns to the front of the feet?

Also, to get the ball to move with the player, you could do a few things.

  1. Don’t parent the ball to the feet. Move the ball ahead by so much based on the angle and speed of the player that touches it. So when a player encounters it, the player pushes the ball forward. That way if you constantly move in one direction the ball will move in that way, but if you angle to turn and move, the ball will head in that direction too.

  2. Parent the ball to the feet. When the player that has it moves forward, don’t move the position till you detect the player colliders with it, then move the ball ahead accordingly. You may need to lerp from the position of collision to the distance you want in front of the player.

Since you mentioned “Realistic” I would argue that you want to have physics actually control the ball movement.
This can be achieved by having the feet have a collider and a rigidbody, and have the ball be a rigid body as well.

You’ll need to add forces, and probably find the proper settings for all bodies involved, but using this method you will get a much closer approximation of what actually happens when you dribble the ball.

1 Like

Please am working something similar. How would the player kick the ball, receive a pass or maybe chest a high pass from another player

what you need to do is every time the animation does the dribble kick, Use an animation event to call a function which will reset all forces on the rigid body of the ball and then adds a force in the direction the player is willing to go, secondly when the player wants to turn do not just turn the player right away I would suggest that the player follow the ball at a constant speed and if we have input just play the animation and follow the ball until it stops, in this method you will add the force to the ball in the direction of the input rather than rotating the player, The player must follow the ball if he has possession and the ball should get a force of the direction the player wants to go every Time the animation event is called, no need for parenting the ball to the player at all, this will make it look really realistic and natural, the amount of force you add will need to be tinkered until you find a force which looks best.