I am creating a simple top-down 3D game where two players run around kicking a soccer ball. I have colliders on the players and the ball, and wrote a simple script to have the players kick the ball whenever they come in contact with it. HOWEVER, I can’t figure out which direction a player is facing when she contacts the ball, and thus which direction the ball should travel. In the following code I used a Vector3.left so that the ball did SOMETHING, but obviously I can’t have a game where everyone kicks the ball left.
How can I tell Which direction is my player facing when she contacts the ball (as in, what can I replace “Vector3.left” in my code with?)
NOTE: Code is attached to each PLAYER, “other game object” is the ball<<
using UnityEngine;
using System.Collections;
public class ShootBall3: MonoBehaviour {
void OnTriggerEnter(Collider other)
{
//facing = Vector3.forward;
if (other.gameObject.tag == "Ball") {
other.rigidbody.AddExplosionForce(2000f, Vector3.left, 2000);
}
}
}