Excuse me if this has been asked, but I've been searching for a long time, and can't seem to find the problem (I'm quite inexperienced as well). If the question has already been answered, feel free to link it.
I have the player creating and moving a projectile (it works exactly how I want it), but the same exact script won't work on the enemy I've created. The enemy and player are exactly the same (to my knowledge), except for the "third person controller" script, and the "character controller".
The enemy will create the projectile, but it won't move. It stays in the middle of the enemy, where it's created.
Player script
var projectile : Transform;
var phealth : int = 3;
function FixedUpdate () {
if (Input.GetButtonDown ("Fire1")) {
var cloneprojectile : GameObject = Instantiate (projectile,
transform.position, transform.rotation);
cloneprojectile.transform.Translate(0,0,.8);
Destroy (cloneprojectile, Time.deltaTime * .001);
}
}
Enemy script
var projectile : Transform;
var ehealth : int = 3;
function FixedUpdate () {
if (Input.GetButtonDown ("Fire2")) {
var eprojectile : GameObject = Instantiate (projectile,
transform.position, transform.rotation);
eprojectile.transform.Translate(0,0,.8);
Destroy (eprojectile, Time.deltaTime * .001);
}
}
The projectile is a trigger, with a kinematic rigidbody to do damage.
I have the error "InvalidCastException: Cannot cast from source type to destination type." on the line
var eprojectile : GameObject = Instantiate (projectile, transform.position,
transform.rotation);
It's just tough because the script works in one case, but not the other.
This is probably really easy for you to answer haha.