Hello,
I'm trying to make a 3rd person shooter (top down view) and I'm stuck with a problem:
I created a basic firing script, wich creates a bullet (prefab) on the player position and fires it to the direction where the mouse is poiting. The code is:
var pfBullet: Transform;
function Update () {
if(Input.GetButtonDown("Fire1")) {
var bullet = Instantiate(pfBullet, transform.position, Quaternion.identity);
bullet.rigidbody.AddForce(transform.forward*2000);
}
}
When the player is not moving, it works fine, the bullet goes to where the mouse is pointing, but when I start moving the character around(I'm using the 3rd person controller), sometimes the shoots goes to random directions, most often when I shoot several times ver quick. I believe that is something with the rotation of the player, so there is any anyway to use the Input.mousePosition on the instantiate instead the Quaternion.identity? There's any way to convert the position?
EDIT: This script does not fire to where the mouse is actually, but the player have a script that turns it to face the mouse on every update. Just noticed I didn't added this info =)