kicking a ball with a first person controller

I am using unity trying to make a soccer game. Have a flat terrain with grass. Have a first person controller. Have a sphere (the ball). Rigidbody physics on the sphere. But, I have no idea how to make the ball move. I want it to move once I run into it with my first person controller and I have tried everything and googled it already. anyone know how to help??? view from far away http://i.imgur.com/vcd9n.png and view from close http://i.imgur.com/4TXk2.png . I need to have the first person controller (capsule) run into the ball and make it move desperately.

3 Answers

3

You can test against the distance between player and ball, and if it is below a certain threshold, you apply a force on the ball. You could additionally test for a player input.

var plChar : Transform;
var threshold: int;
var power;

if((transform.position - plChar.transform.position).magnitude < threshold) {
    rigidBody.AddForce((transform.position - plChar.transform.position).normalized * power); 
}

This would be a script for the ball. Pull the player into the Transform Slot via the Inspector.

you need animate the player running with ball

The First Person Controller uses a CharacterController. To get a character controller to hit something you can use OnControllerColliderHit(). The example script on the manual page contains an example script for pushing an object. Just up pushPower for a kick. Note after you get the kick working, if you want to add some curve, see this post:

http://answers.unity3d.com/questions/377944/how-to-make-a-ball-rotate-as-per-its-moving-direct.html