- Home /
Question by
dermanko · Mar 01, 2015 at 09:58 AM ·
prefabprojectilemotion
Enemy shooting problem
I want to make the enemy shoot projectiles at the player but instead it turns into the projectile and comes at the player can somebody help?
Here is my code
#pragma strict
var AimDistance = 25.0;
var shootRange = 15.0;
var enemyBullet : Rigidbody;
var EnemyBulletSpeed = 15f;
var TargetPlayer : Transform;
var ShootDistance = 10f;
function Update () {
ShootDistance = Vector3.Distance(TargetPlayer.position, transform.position);
if (ShootDistance < shootRange ) {
var clone = Instantiate(enemyBullet, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection(Vector3(0, 0, EnemyBulletSpeed));
transform.Translate(Vector3.forward * AimDistance * Time.deltaTime);
Destroy (clone.gameObject, 3);
}
}
Comment
What do you think this line is doing?
transform.Translate(Vector3.forward * AimDistance * Time.deltaTime);
Your answer
Follow this Question
Related Questions
Add Motion Blur To Prefab - HELP 2 Answers
Game not working when I save, exit out of unity, then come back in. 1 Answer
My chain hit goes to the center of the map, why? 0 Answers
How to instantiate a projectile only from the weapon prefab of the firing player? 1 Answer
spell prefab recycling 0 Answers